Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stripIgnoredTokens feature to remove insignificant whitespace #1628

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,861 changes: 5,861 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/__fixtures__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ export const bigSchemaIntrospectionResult = JSON.parse(

export const kitchenSinkSDL = readLocalFile('schema-kitchen-sink.graphql');
export const kitchenSinkQuery = readLocalFile('kitchen-sink.graphql');

function removeCommentsFromFixture(fixture) {
return fixture.replace(/#.*/g, '');
}

export const strippedKitchenSinkSDL = removeCommentsFromFixture(
readLocalFile('stripped-schema-kitchen-sink.graphql'),
).trim();
export const strippedKitchenSinkQuery = removeCommentsFromFixture(
readLocalFile('stripped-kitchen-sink.graphql'),
).trim();
8 changes: 8 additions & 0 deletions src/__fixtures__/stripped-kitchen-sink.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2015-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

query queryName($foo:ComplexType$site:Site=MOBILE)@onQuery{whoever123is:node(id:[123 456]){id...on User@onInlineFragment{field2{id alias:field1(first:10 after:$foo)@include(if:$foo){id...frag@onFragmentSpread}}}...@skip(unless:$foo){id}...{id}}}mutation likeStory@onMutation{like(story:123)@onField{story{id@onField}}}subscription StoryLikeSubscription($input:StoryLikeSubscribeInput)@onSubscription{storyLikeSubscribe(input:$input){story{likers{count}likeSentence{text}}}}fragment frag on Friend@onFragmentDefinition{foo(size:$size bar:$b obj:{key:"value" block:"""
block string uses \"""
"""})}{unnamed(truthy:true falsey:false nullish:null)query}{__typename}
21 changes: 21 additions & 0 deletions src/__fixtures__/stripped-schema-kitchen-sink.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2015-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

schema{query:QueryType mutation:MutationType}"""
This is a description
of the `Foo` type.
""" type Foo implements Bar&Baz{"Description of the `one` field." one:Type """
This is a description of the `two` field.
""" two("""
This is a description of the `argument` argument.
""" argument:InputType!):Type """
This is a description of the `three` field.
""" three(argument:InputType other:String):Int four(argument:String="string"):String five(argument:[String]=["string" "string"]):String six(argument:InputType={key:"value"}):Type seven(argument:Int=null):Type}type AnnotatedObject@onObject(arg:"value"){annotatedField(arg:Type="default"@onArgumentDefinition):Type@onField}type UndefinedType extend type Foo{seven(argument:[String]):Type}extend type Foo@onType interface Bar{one:Type four(argument:String="string"):String}interface AnnotatedInterface@onInterface{annotatedField(arg:Type@onArgumentDefinition):Type@onField}interface UndefinedInterface extend interface Bar{two(argument:InputType!):Type}extend interface Bar@onInterface union Feed=Story|Article|Advert union AnnotatedUnion@onUnion=A|B union AnnotatedUnionTwo@onUnion=A|B union UndefinedUnion extend union Feed=Photo|Video extend union Feed@onUnion scalar CustomScalar scalar AnnotatedScalar@onScalar extend scalar CustomScalar@onScalar enum Site{"""
This is a description of the `DESKTOP` value
""" DESKTOP """
This is a description of the `MOBILE` value
""" MOBILE "This is a description of the `WEB` value" WEB}enum AnnotatedEnum@onEnum{ANNOTATED_VALUE@onEnumValue OTHER_VALUE}enum UndefinedEnum extend enum Site{VR}extend enum Site@onEnum input InputType{key:String!answer:Int=42}input AnnotatedInput@onInputObject{annotatedField:Type@onInputFieldDefinition}input UndefinedInput extend input InputType{other:Float=1.23e4@onInputFieldDefinition}extend input InputType@onInputObject """
This is a description of the `@skip` directive
""" directive@skip(if:Boolean!@onArgumentDefinition)on FIELD|FRAGMENT_SPREAD|INLINE_FRAGMENT directive@include(if:Boolean!)on FIELD|FRAGMENT_SPREAD|INLINE_FRAGMENT directive@include2(if:Boolean!)on FIELD|FRAGMENT_SPREAD|INLINE_FRAGMENT extend schema@onSchema extend schema@onSchema{subscription:SubscriptionType}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ export {
concatAST,
// Separates an AST into an AST per Operation.
separateOperations,
// Strips insignificant tokens from a GraphQL string.
stripIgnoredTokens,
// Comparators for types
isEqualType,
isTypeSubTypeOf,
Expand Down
Loading