...

Text file src/github.com/vektah/gqlparser/v2/parser/query_test.yml

Documentation: github.com/vektah/gqlparser/v2/parser

     1parser provides useful errors:
     2  - name: unclosed paren
     3    input: '{'
     4    error:
     5      message: "Expected Name, found <EOF>"
     6      locations: [{line: 1, column: 2}]
     7
     8  - name: missing on in fragment
     9    input: |
    10      { ...MissingOn }
    11      fragment MissingOn Type
    12    error:
    13      message: 'Expected "on", found Name "Type"'
    14      locations: [{ line: 2, column: 20 }]
    15
    16  - name: missing name after alias
    17    input: '{ field: {} }'
    18    error:
    19      message: "Expected Name, found {"
    20      locations: [{ line: 1, column: 10 }]
    21
    22  - name: not an operation
    23    input: 'notanoperation Foo { field }'
    24    error:
    25      message: 'Unexpected Name "notanoperation"'
    26      locations: [{ line: 1, column: 1 }]
    27
    28  - name: a wild splat appears
    29    input: '...'
    30    error:
    31      message: 'Unexpected ...'
    32      locations: [{ line: 1, column: 1}]
    33
    34variables:
    35  - name: are allowed in args
    36    input: '{ field(complex: { a: { b: [ $var ] } }) }'
    37
    38  - name: are not allowed in default args
    39    input: 'query Foo($x: Complex = { a: { b: [ $var ] } }) { field }'
    40    error:
    41      message: 'Unexpected $'
    42      locations: [{ line: 1, column: 37 }]
    43
    44  - name: can have directives
    45    input: 'query ($withDirective: String @first @second, $withoutDirective: String) { f }'
    46    ast: |
    47      <QueryDocument>
    48        Operations: [OperationDefinition]
    49        - <OperationDefinition>
    50            Operation: Operation("query")
    51            VariableDefinitions: [VariableDefinition]
    52            - <VariableDefinition>
    53                Variable: "withDirective"
    54                Type: String
    55                Directives: [Directive]
    56                - <Directive>
    57                    Name: "first"
    58                - <Directive>
    59                    Name: "second"
    60            - <VariableDefinition>
    61                Variable: "withoutDirective"
    62                Type: String
    63            SelectionSet: [Selection]
    64            - <Field>
    65                Alias: "f"
    66                Name: "f"
    67
    68fragments:
    69  - name: can not be named 'on'
    70    input: 'fragment on on on { on }'
    71    error:
    72      message: 'Unexpected Name "on"'
    73      locations: [{ line: 1, column: 10 }]
    74
    75  - name: can not spread fragments called 'on'
    76    input: '{ ...on }'
    77    error:
    78      message: 'Expected Name, found }'
    79      locations: [{ line: 1, column: 9 }]
    80
    81encoding:
    82  - name: multibyte characters are supported
    83    input: |
    84      # This comment has a ਊ multi-byte character.
    85      { field(arg: "Has a ਊ multi-byte character.") }
    86    ast: |
    87      <QueryDocument>
    88        Operations: [OperationDefinition]
    89        - <OperationDefinition>
    90            Operation: Operation("query")
    91            SelectionSet: [Selection]
    92            - <Field>
    93                Alias: "field"
    94                Name: "field"
    95                Arguments: [Argument]
    96                - <Argument>
    97                    Name: "arg"
    98                    Value: "Has a ਊ multi-byte character."
    99
   100keywords are allowed anywhere a name is:
   101  - name: on
   102    input: |
   103      query on {
   104        ... a
   105        ... on on { field }
   106      }
   107      fragment a on Type {
   108        on(on: $on)
   109          @on(on: on)
   110      }
   111
   112  - name: subscription
   113    input: |
   114      query subscription {
   115        ... subscription
   116        ... on subscription { field }
   117      }
   118      fragment subscription on Type {
   119        subscription(subscription: $subscription)
   120          @subscription(subscription: subscription)
   121      }
   122
   123  - name: true
   124    input: |
   125      query true {
   126        ... true
   127        ... on true { field }
   128      }
   129      fragment true on Type {
   130        true(true: $true)
   131          @true(true: true)
   132      }
   133
   134operations:
   135  - name: anonymous mutation
   136    input: 'mutation { mutationField }'
   137
   138  - name: named mutation
   139    input: 'mutation Foo { mutationField }'
   140
   141  - name: anonymous subscription
   142    input: 'subscription { subscriptionField }'
   143
   144  - name: named subscription
   145    input: 'subscription Foo { subscriptionField }'
   146
   147
   148ast:
   149  - name: simple query
   150    input: |
   151      {
   152        node(id: 4) {
   153          id,
   154          name
   155        }
   156      }
   157    ast: |
   158      <QueryDocument>
   159        Operations: [OperationDefinition]
   160        - <OperationDefinition>
   161            Operation: Operation("query")
   162            SelectionSet: [Selection]
   163            - <Field>
   164                Alias: "node"
   165                Name: "node"
   166                Arguments: [Argument]
   167                - <Argument>
   168                    Name: "id"
   169                    Value: 4
   170                SelectionSet: [Selection]
   171                - <Field>
   172                    Alias: "id"
   173                    Name: "id"
   174                - <Field>
   175                    Alias: "name"
   176                    Name: "name"
   177
   178  - name: nameless query with no variables
   179    input: |
   180      query {
   181        node {
   182          id
   183        }
   184      }
   185    ast: |
   186      <QueryDocument>
   187        Operations: [OperationDefinition]
   188        - <OperationDefinition>
   189            Operation: Operation("query")
   190            SelectionSet: [Selection]
   191            - <Field>
   192                Alias: "node"
   193                Name: "node"
   194                SelectionSet: [Selection]
   195                - <Field>
   196                    Alias: "id"
   197                    Name: "id"
   198
   199  - name: fragment defined variables
   200    input: 'fragment a($v: Boolean = false) on t { f(v: $v) }'
   201    ast: |
   202      <QueryDocument>
   203        Fragments: [FragmentDefinition]
   204        - <FragmentDefinition>
   205            Name: "a"
   206            VariableDefinition: [VariableDefinition]
   207            - <VariableDefinition>
   208                Variable: "v"
   209                Type: Boolean
   210                DefaultValue: false
   211            TypeCondition: "t"
   212            SelectionSet: [Selection]
   213            - <Field>
   214                Alias: "f"
   215                Name: "f"
   216                Arguments: [Argument]
   217                - <Argument>
   218                    Name: "v"
   219                    Value: $v
   220
   221
   222values:
   223  - name: null
   224    input: '{ f(id: null) }'
   225    ast: |
   226      <QueryDocument>
   227        Operations: [OperationDefinition]
   228        - <OperationDefinition>
   229            Operation: Operation("query")
   230            SelectionSet: [Selection]
   231            - <Field>
   232                Alias: "f"
   233                Name: "f"
   234                Arguments: [Argument]
   235                - <Argument>
   236                    Name: "id"
   237                    Value: null
   238
   239  - name: strings
   240    input: '{ f(long: """long""", short: "short") } '
   241    ast: |
   242      <QueryDocument>
   243        Operations: [OperationDefinition]
   244        - <OperationDefinition>
   245            Operation: Operation("query")
   246            SelectionSet: [Selection]
   247            - <Field>
   248                Alias: "f"
   249                Name: "f"
   250                Arguments: [Argument]
   251                - <Argument>
   252                    Name: "long"
   253                    Value: "long"
   254                - <Argument>
   255                    Name: "short"
   256                    Value: "short"
   257
   258  - name: list
   259    input: '{ f(id: [1,2]) }'
   260    ast: |
   261      <QueryDocument>
   262        Operations: [OperationDefinition]
   263        - <OperationDefinition>
   264            Operation: Operation("query")
   265            SelectionSet: [Selection]
   266            - <Field>
   267                Alias: "f"
   268                Name: "f"
   269                Arguments: [Argument]
   270                - <Argument>
   271                    Name: "id"
   272                    Value: [1,2]
   273
   274types:
   275  - name: common types
   276    input: 'query ($string: String, $int: Int, $arr: [Arr], $notnull: [Arr!]!) { f }'
   277    ast: |
   278      <QueryDocument>
   279        Operations: [OperationDefinition]
   280        - <OperationDefinition>
   281            Operation: Operation("query")
   282            VariableDefinitions: [VariableDefinition]
   283            - <VariableDefinition>
   284                Variable: "string"
   285                Type: String
   286            - <VariableDefinition>
   287                Variable: "int"
   288                Type: Int
   289            - <VariableDefinition>
   290                Variable: "arr"
   291                Type: [Arr]
   292            - <VariableDefinition>
   293                Variable: "notnull"
   294                Type: [Arr!]!
   295            SelectionSet: [Selection]
   296            - <Field>
   297                Alias: "f"
   298                Name: "f"
   299
   300large queries:
   301  - name: kitchen sink
   302    input: |
   303      # Copyright (c) 2015-present, Facebook, Inc.
   304      #
   305      # This source code is licensed under the MIT license found in the
   306      # LICENSE file in the root directory of this source tree.
   307
   308      query queryName($foo: ComplexType, $site: Site = MOBILE) {
   309        whoever123is: node(id: [123, 456]) {
   310          id ,
   311          ... on User @defer {
   312            field2 {
   313              id ,
   314              alias: field1(first:10, after:$foo,) @include(if: $foo) {
   315                id,
   316                ...frag
   317              }
   318            }
   319          }
   320          ... @skip(unless: $foo) {
   321            id
   322          }
   323          ... {
   324            id
   325          }
   326        }
   327      }
   328
   329      mutation likeStory {
   330        like(story: 123) @defer {
   331          story {
   332            id
   333          }
   334        }
   335      }
   336
   337      subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
   338        storyLikeSubscribe(input: $input) {
   339          story {
   340            likers {
   341              count
   342            }
   343            likeSentence {
   344              text
   345            }
   346          }
   347        }
   348      }
   349
   350      fragment frag on Friend {
   351        foo(size: $size, bar: $b, obj: {key: "value", block: """
   352            block string uses \"""
   353        """})
   354      }
   355
   356      {
   357        unnamed(truthy: true, falsey: false, nullish: null),
   358        query
   359      }
   360    ast: |
   361      <QueryDocument>
   362        Operations: [OperationDefinition]
   363        - <OperationDefinition>
   364            Operation: Operation("query")
   365            Name: "queryName"
   366            VariableDefinitions: [VariableDefinition]
   367            - <VariableDefinition>
   368                Variable: "foo"
   369                Type: ComplexType
   370            - <VariableDefinition>
   371                Variable: "site"
   372                Type: Site
   373                DefaultValue: MOBILE
   374            SelectionSet: [Selection]
   375            - <Field>
   376                Alias: "whoever123is"
   377                Name: "node"
   378                Arguments: [Argument]
   379                - <Argument>
   380                    Name: "id"
   381                    Value: [123,456]
   382                SelectionSet: [Selection]
   383                - <Field>
   384                    Alias: "id"
   385                    Name: "id"
   386                - <InlineFragment>
   387                    TypeCondition: "User"
   388                    Directives: [Directive]
   389                    - <Directive>
   390                        Name: "defer"
   391                    SelectionSet: [Selection]
   392                    - <Field>
   393                        Alias: "field2"
   394                        Name: "field2"
   395                        SelectionSet: [Selection]
   396                        - <Field>
   397                            Alias: "id"
   398                            Name: "id"
   399                        - <Field>
   400                            Alias: "alias"
   401                            Name: "field1"
   402                            Arguments: [Argument]
   403                            - <Argument>
   404                                Name: "first"
   405                                Value: 10
   406                            - <Argument>
   407                                Name: "after"
   408                                Value: $foo
   409                            Directives: [Directive]
   410                            - <Directive>
   411                                Name: "include"
   412                                Arguments: [Argument]
   413                                - <Argument>
   414                                    Name: "if"
   415                                    Value: $foo
   416                            SelectionSet: [Selection]
   417                            - <Field>
   418                                Alias: "id"
   419                                Name: "id"
   420                            - <FragmentSpread>
   421                                Name: "frag"
   422                - <InlineFragment>
   423                    Directives: [Directive]
   424                    - <Directive>
   425                        Name: "skip"
   426                        Arguments: [Argument]
   427                        - <Argument>
   428                            Name: "unless"
   429                            Value: $foo
   430                    SelectionSet: [Selection]
   431                    - <Field>
   432                        Alias: "id"
   433                        Name: "id"
   434                - <InlineFragment>
   435                    SelectionSet: [Selection]
   436                    - <Field>
   437                        Alias: "id"
   438                        Name: "id"
   439            Comment: "# Copyright (c) 2015-present, Facebook, Inc.\n#\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n"
   440        - <OperationDefinition>
   441            Operation: Operation("mutation")
   442            Name: "likeStory"
   443            SelectionSet: [Selection]
   444            - <Field>
   445                Alias: "like"
   446                Name: "like"
   447                Arguments: [Argument]
   448                - <Argument>
   449                    Name: "story"
   450                    Value: 123
   451                Directives: [Directive]
   452                - <Directive>
   453                    Name: "defer"
   454                SelectionSet: [Selection]
   455                - <Field>
   456                    Alias: "story"
   457                    Name: "story"
   458                    SelectionSet: [Selection]
   459                    - <Field>
   460                        Alias: "id"
   461                        Name: "id"
   462        - <OperationDefinition>
   463            Operation: Operation("subscription")
   464            Name: "StoryLikeSubscription"
   465            VariableDefinitions: [VariableDefinition]
   466            - <VariableDefinition>
   467                Variable: "input"
   468                Type: StoryLikeSubscribeInput
   469            SelectionSet: [Selection]
   470            - <Field>
   471                Alias: "storyLikeSubscribe"
   472                Name: "storyLikeSubscribe"
   473                Arguments: [Argument]
   474                - <Argument>
   475                    Name: "input"
   476                    Value: $input
   477                SelectionSet: [Selection]
   478                - <Field>
   479                    Alias: "story"
   480                    Name: "story"
   481                    SelectionSet: [Selection]
   482                    - <Field>
   483                        Alias: "likers"
   484                        Name: "likers"
   485                        SelectionSet: [Selection]
   486                        - <Field>
   487                            Alias: "count"
   488                            Name: "count"
   489                    - <Field>
   490                        Alias: "likeSentence"
   491                        Name: "likeSentence"
   492                        SelectionSet: [Selection]
   493                        - <Field>
   494                            Alias: "text"
   495                            Name: "text"
   496        - <OperationDefinition>
   497            Operation: Operation("query")
   498            SelectionSet: [Selection]
   499            - <Field>
   500                Alias: "unnamed"
   501                Name: "unnamed"
   502                Arguments: [Argument]
   503                - <Argument>
   504                    Name: "truthy"
   505                    Value: true
   506                - <Argument>
   507                    Name: "falsey"
   508                    Value: false
   509                - <Argument>
   510                    Name: "nullish"
   511                    Value: null
   512            - <Field>
   513                Alias: "query"
   514                Name: "query"
   515        Fragments: [FragmentDefinition]
   516        - <FragmentDefinition>
   517            Name: "frag"
   518            TypeCondition: "Friend"
   519            SelectionSet: [Selection]
   520            - <Field>
   521                Alias: "foo"
   522                Name: "foo"
   523                Arguments: [Argument]
   524                - <Argument>
   525                    Name: "size"
   526                    Value: $size
   527                - <Argument>
   528                    Name: "bar"
   529                    Value: $b
   530                - <Argument>
   531                    Name: "obj"
   532                    Value: {key:"value",block:"block string uses \"\"\""}
   533
   534fuzzer:
   535- name: 01
   536  input: '{__typename{...}}'
   537  error:
   538    message: 'Expected {, found }'
   539    locations: [{ line: 1, column: 16 }]
   540
   541- name: 02
   542  input: '{...{__typename{...{}}}}'
   543  error:
   544    message: 'expected at least one definition, found }'
   545    locations: [{ line: 1, column: 21 }]

View as plain text