github.com/dgraph-io/dgraph@v1.2.8/graphql/schema/gqlschema_test.yml (about)

     1  invalid_schemas:
     2    -
     3      name: "More than 1 id field"
     4      input: |
     5        type P {
     6          id1: ID!
     7          id2: ID!
     8          id3: ID!
     9        }
    10      errlist: [
    11        {"message":"Fields id1, id2 and id3 are listed as IDs for type P, but a type can have only one ID field. Pick a single field as the ID for type P.", "locations":[{"line":2, "column":3}, {"line":3, "column":3}, {"line":4, "column":3}]},
    12      ]
    13  
    14    -
    15      name: "UID as a field name"
    16      input: |
    17        type P {
    18          uid: String
    19        }
    20      errlist: [
    21        {"message":"Type P; Field uid: uid is a reserved keyword and you cannot declare a field with this name.", "locations": [{"line":2, "column": 3}]},
    22      ]
    23  
    24    -
    25      name: "Query, Mutation in initial schema"
    26      input: |
    27        type Query {
    28          getAuthro(id: ID): Author!
    29        }
    30        type Mutation {
    31          getAuthro(id: ID): Author!
    32        }
    33      errlist: [
    34        {"message":"You don't need to define the GraphQL Query or Mutation types. Those are built automatically for you.", "locations":[{"line":1, "column":6}]},
    35        {"message":"You don't need to define the GraphQL Query or Mutation types. Those are built automatically for you.", "locations":[{"line":4, "column":6}]},
    36      ]
    37  
    38    -
    39      name: "No ID list of any kind"
    40      input: |
    41        type A {
    42          f: [ID]
    43        }
    44      errlist: [
    45        {"message": "Type A; Field f: ID lists are invalid.", "locations": [{"line":2, "column": 3}]}
    46      ]
    47  
    48  
    49    -
    50      name: "No nested list of any kind"
    51      input: |
    52        type A {
    53          f: [[String]]
    54        }
    55      errlist: [
    56        {"message": "Type A; Field f: Nested lists are invalid.", "locations": [{"line":2, "column": 3}]}
    57      ]
    58  
    59    -
    60      name: "There shoudnt be arguments on any field"
    61      input: |
    62        type T {
    63          f(a: Int): String
    64        }
    65      errlist: [
    66        {"message": "Type T; Field f: You can't give arguments to fields.", "locations": [{"line": 2, "column": 3}]}
    67      ]
    68  
    69    -
    70      name: "Enum indexes clash trigram and regexp"
    71      input: |
    72        type T {
    73          f: E @search(by: [trigram, regexp])
    74        }
    75        enum E {
    76          A
    77        }
    78      errlist: [
    79        {"message": "Type T; Field f: the argument to @search 'trigram' is the same as the index 'regexp' provided before and shouldn't be used together",
    80        "locations": [{"line": 2, "column": 9}]}
    81      ]
    82  
    83    -
    84      name: "Enum indexes clash hash and exact"
    85      input: |
    86        type T {
    87          f: E @search(by: [hash, exact])
    88        }
    89        enum E {
    90          A
    91        }
    92      errlist: [
    93        {"message": "Type T; Field f: the arguments 'hash' and 'exact' can't be used together as arguments to @search.", "locations": [{"line": 2, "column": 9}]}
    94      ]
    95  
    96    -
    97      name: "Reference type that is not in input schema"
    98      input: |
    99        type T {
   100            f: Author
   101        }
   102      errlist: [
   103        {"message": "Undefined type Author.", "locations": [{"line": 2, "column": 8}]}
   104      ]
   105  
   106    -
   107      name: "Unsupported definitions in initial schema"
   108      input: |
   109        scalar Int
   110        interface P {
   111          t: T!
   112        }
   113        union Q = R | S | T
   114        input U {
   115          x: X!
   116        }
   117      errlist: [
   118        {"message":"You can't add scalar definitions. Only type, interface and enums are allowed in initial schema.", "locations":[{"line":1, "column":8}]},
   119        {"message":"You can't add union definitions. Only type, interface and enums are allowed in initial schema.", "locations":[{"line":5, "column":7}]},
   120        {"message":"You can't add input_object definitions. Only type, interface and enums are allowed in initial schema.", "locations":[{"line":6, "column":7}]},
   121      ]
   122  
   123    -
   124      name: "Typename is reserved word"
   125      input: |
   126        type String {
   127          id: ID!
   128        }
   129      errlist: [
   130        {"message":"String is a reserved word, so you can't declare a type with this name. Pick a different name for the type.", "locations":[{"line":1, "column":6}]},
   131      ]
   132  
   133    -
   134      name: "More than 1 errors"
   135      input: |
   136        type X {
   137          i1: ID!
   138          i2: ID!
   139          i3: ID!
   140          l1: [X]!
   141          l2: [ID]
   142        }
   143      errlist: [
   144        {"message":"Fields i1, i2, i3 and l2 are listed as IDs for type X, but a type can have only one ID field. Pick a single field as the ID for type X.", "locations":[{"line":2, "column":3}, {"line":3, "column":3}, {"line":4, "column":3}, {"line":6, "column": 3}]},
   145        {"message": "Type X; Field l2: ID lists are invalid.", "locations": [{"line": 6, "column": 3}]}
   146      ]
   147  
   148    -
   149      name: "Union type in schema"
   150      input: |
   151        union U = R | S | T
   152      errlist: [
   153        {"message":"You can't add union definitions. Only type, interface and enums are allowed in initial schema.", "locations":[{"line":1, "column":7}]}
   154      ]
   155  
   156    -
   157      name: "Non linking inverse directive with correct field type"
   158      input: |
   159        type Post {
   160          author: Author! @hasInverse(field: "posts")
   161          likedBy: Author
   162        }
   163        type Author {
   164          posts: [Post!]! @hasInverse(field: likedBy)
   165        }
   166      errlist: [
   167        {"message": "Type Post; Field author: @hasInverse should be consistant. Post.author is the inverse of Author.posts, but Author.posts is the inverse of Post.likedBy.", "locations": [{"line": 2, "column": 20}]}
   168      ]
   169  
   170    -
   171      name: "Multiple hasInverse to one field"
   172      input: |
   173        type Post {
   174          author: Author! @hasInverse(field: "posts")
   175          likedBy: Author @hasInverse(field: "posts")
   176        }
   177  
   178        type Author {
   179          posts: [Post!]!
   180        }
   181      errlist: [
   182        {"message": "Type Post; Field likedBy: @hasInverse should be consistant. Post.likedBy is the inverse of Author.posts, but Author.posts is the inverse of Post.author.", "locations": [{"line": 3, "column": 20}]}
   183      ]
   184  
   185    -
   186      name: "Non linking inverse directives"
   187      input: |
   188        type X {
   189          f1: P @hasInverse(field: "f1")
   190          f2: String
   191        }
   192        type P {
   193          f1: X @hasInverse(field: "f2")
   194        }
   195      errlist: [
   196        {"message":"Type X; Field f1: @hasInverse should be consistant. X.f1 is the inverse of P.f1, but P.f1 is the inverse of X.f2.", "locations":[{"line":2, "column":10}]},
   197        {"message":"Type P; Field f1: @hasInverse is required to link the fields of same type, but the field f2 is of the type String instead of P. To link these make sure the fields are of the same type.", "locations":[{"line":6, "column":10}]},
   198      ]
   199  
   200    -
   201      name: "Inverse Directive on non object field"
   202      input: |
   203        type X {
   204          f1: String @hasInverse(field: "f1")
   205        }
   206      errlist: [
   207        {"message":"Type X; Field f1: Field f1 is of type String, but @hasInverse directive only applies to fields with object types.", "locations":[{"line":2, "column":3}]},
   208      ]
   209  
   210    -
   211      name: "Inverse Directive doesn't have field argument"
   212      input: |
   213        type X {
   214          f1: X @hasInverse
   215        }
   216      errlist: [
   217        {"message":"Type X; Field f1: @hasInverse directive doesn't have field argument.", "locations":[{"line":2, "column":10}]},
   218      ]
   219  
   220    -
   221      name: "hasInverse on non existing field"
   222      input: |
   223        type X {
   224          f1: [P!]! @hasInverse(field: "f2")
   225        }
   226        type P  {
   227          f1: String
   228        }
   229      errlist: [
   230        {"message":"Type X; Field f1: inverse field f2 doesn't exist for type P.", "locations":[{"line":2, "column":14}]},
   231      ]
   232  
   233    -
   234      name: "ID can't have the @search directive"
   235      input: |
   236        type X {
   237          id: ID! @search
   238        }
   239        type Y {
   240          id: ID! @search(by: [term])
   241        }
   242      errlist: [
   243        {"message": "Type X; Field id: has the @search directive but fields of type ID can't
   244            have the @search directive.",
   245        "locations":[{"line":2, "column":12}]},
   246        {"message": "Type Y; Field id: has the @search directive but the argument term doesn't
   247            apply to field type ID.  Search by term applies to fields of type String. Fields of type
   248            ID can't have the @search directive.",
   249        "locations":[{"line":5, "column":12}]}
   250        ]
   251  
   252    -
   253      name: "Search will error on type that can't have the @search"
   254      input: |
   255        type X {
   256          y: Y @search
   257        }
   258        type Y {
   259          y: String
   260        }
   261      errlist: [
   262        {"message": "Type X; Field y: has the @search directive but fields of type Y
   263            can't have the @search directive.",
   264        "locations":[{"line":2, "column":9}]}
   265        ]
   266  
   267    -
   268      name: "Search (with arg) will error that can't have the @search"
   269      input: |
   270        type X {
   271          y: Y @search(by: [term])
   272        }
   273        type Y {
   274          y: String
   275        }
   276      errlist: [
   277        {"message": "Type X; Field y: has the @search directive but the argument term doesn't
   278            apply to field type Y.  Search by term applies to fields of type String. Fields of
   279            type Y can't have the @search directive.",
   280        "locations":[{"line":2, "column":9}]}
   281        ]
   282  
   283    -
   284      name: "Search with wrong arg with error on default search type"
   285      input: |
   286        type X {
   287          y: Int @search(by: [term])
   288        }
   289      errlist: [
   290        {"message": "Type X; Field y: has the @search directive but the argument term doesn't
   291            apply to field type Int.  Search by term applies to fields of type String. Fields of
   292            type Int are searchable by just @search.",
   293        "locations":[{"line":2, "column":11}]}
   294        ]
   295  
   296    -
   297      name: "Search with wrong arg with error on search type"
   298      input: |
   299        type X {
   300          y: String @search(by: [day])
   301        }
   302      errlist: [
   303        {"message": "Type X; Field y: has the @search directive but the argument day doesn't
   304            apply to field type String.  Search by day applies to fields of type DateTime. Fields
   305            of type String can have @search by exact, fulltext, hash, regexp, term and trigram.",
   306        "locations":[{"line":2, "column":14}]}
   307        ]
   308  
   309    -
   310      name: "Search with wrong arg for the index"
   311      input: |
   312        type X {
   313          y: String @search(by: [hash, hour])
   314        }
   315      errlist: [
   316        {"message": "Type X; Field y: has the @search directive but the argument hour doesn't
   317            apply to field type String.  Search by hour applies to fields of type DateTime. Fields
   318            of type String can have @search by exact, fulltext, hash, regexp, term and trigram.",
   319        "locations":[{"line":2, "column":14}]}
   320        ]
   321  
   322    -
   323      name: "Search without []"
   324      input: |
   325        type X {
   326          y: String @search(by: hash)
   327        }
   328      errlist: [
   329        {"message": "Type X; Field y: the @search directive requires a list argument,
   330            like @search(by: [hash])",
   331        "locations":[{"line":2, "column":14}]}
   332        ]
   333  
   334    -
   335      name: "Search doesn't allow hash and exact together"
   336      input: |
   337        type X {
   338          y: String @search(by: [hash, exact])
   339        }
   340      errlist: [
   341        {"message": "Type X; Field y: the arguments 'hash' and 'exact' can't be
   342            used together as arguments to @search.",
   343        "locations":[{"line":2, "column":14}]}
   344        ]
   345  
   346    -
   347      name: "Search with multiple datetime index"
   348      input: |
   349        type X {
   350          y: DateTime @search(by: [hour, month])
   351        }
   352      errlist: [
   353        {"message": "Type X; Field y: has the search directive on DateTime. DateTime
   354             allows only one argument for @search.",
   355        "locations":[{"line":2, "column":16}]}
   356        ]
   357  
   358    -
   359      name: "Search doesn't allow trigram and regexp together"
   360      input: |
   361        type X {
   362          y: String @search(by: [trigram, regexp])
   363        }
   364      errlist: [
   365        {"message": "Type X; Field y: the argument to @search 'trigram' is the same as
   366            the index 'regexp' provided before and shouldn't be used together",
   367        "locations":[{"line":2, "column":14}]}
   368        ]
   369  
   370    -
   371      name: "Search doesn't accept bogus args"
   372      input: |
   373        type X {
   374          y: String @search(by: [bogus])
   375        }
   376      errlist: [
   377        {"message": "Type X; Field y: the argument to @search bogus isn't valid.Fields of type
   378            String can have @search by exact, fulltext, hash, regexp, term and trigram.",
   379        "locations":[{"line":2, "column":14}]}
   380        ]
   381  
   382    -
   383      name: "Type implements an interface which wasn't defined"
   384      input: |
   385        type X implements Y {
   386          y: String
   387        }
   388      errlist: [
   389        {"message": Undefined type "Y".,
   390        "locations":[{"line":1, "column":6}]}
   391        ]
   392  
   393    -
   394      name: "Type implements an interface with the field definition repeated"
   395      input: |
   396        interface Y {
   397          id: ID
   398        }
   399        type X implements Y {
   400          id: ID
   401          y: String
   402        }
   403      errlist: [
   404        {"message": "Field X.id can only be defined once.",
   405        "locations":[{"line":5, "column":3}]}
   406        ]
   407  
   408    -
   409      name: "Type implements an interface with the field name repeated but different type"
   410      input: |
   411        interface Y {
   412          id: ID
   413        }
   414        type X implements Y {
   415          id: String
   416          y: String
   417        }
   418      errlist: [
   419        {"message": "Field X.id can only be defined once.",
   420        "locations":[{"line":5, "column":3}]}
   421        ]
   422  
   423    -
   424      name: "Type implements an interface with no field of its own"
   425      input: |
   426        interface Y {
   427          id: ID
   428        }
   429        type X implements Y {
   430        }
   431      errlist: [
   432        {"message": "expected at least one definition, found }",
   433        "locations":[{"line":5, "column":1}]}
   434        ]
   435  
   436    -
   437      name: "Type implements from two interfaces where both have ID"
   438      input: |
   439        interface X {
   440          id: ID
   441        }
   442        interface Y {
   443          id: ID
   444        }
   445        type Z implements X & Y {
   446          name: String
   447        }
   448      errlist: [
   449        {"message": "Field Z.id can only be defined once.",
   450        "locations":[{"line":2, "column":3}]}
   451        ]
   452  
   453    -
   454      name: "List of Boolean is not allowed"
   455      input: |
   456        type X {
   457          q: [Boolean]
   458        }
   459      errlist: [
   460        {"message": "Type X; Field q: Boolean lists are invalid.",
   461        "locations":[{"line":2, "column":3}]}
   462        ]
   463  
   464    -
   465      name: "ID field can't have @dgraph directive"
   466      input: |
   467        type X {
   468          id: ID @dgraph(pred: "X.id")
   469          name: String
   470        }
   471      errlist: [
   472        {"message": "Type X; Field id: has the @dgraph directive but fields of type ID can't
   473            have the @dgraph directive.",
   474        "locations":[{"line":2, "column":11}]}
   475      ]
   476  
   477    -
   478      name: "Field with @id directive has wrong type"
   479      input: |
   480        type X {
   481          f1: [String] @id
   482        }
   483      errlist: [
   484        {"message": "Type X; Field f1: with @id directive must be of type String!, not [String]",
   485        "locations":[{"line":2, "column":17}]}
   486        ]
   487  
   488    -
   489      name: "Field with @id directive should be mandatory"
   490      input: |
   491        type X {
   492          f1: String @id
   493        }
   494      errlist: [
   495        {"message": "Type X; Field f1: with @id directive must be of type String!, not String",
   496        "locations":[{"line":2, "column":15}]}
   497        ]
   498  
   499    -
   500      name: "Field with multiple @id directives should not be allowed"
   501      input: |
   502        type X {
   503          f1: String! @id
   504          f2: String! @id
   505        }
   506      errlist: [
   507        {"message": "Type X: fields f1 and f2 have the @id directive, but a type can
   508          have only one field with @id. Pick a single field with @id for type X.",
   509        "locations":[{"line":2, "column":3},{"line":3, "column":3}]}
   510        ]
   511  
   512    -
   513      name: "Dgraph directive with wrong argument produces an error"
   514      input: |
   515        type X {
   516          f1: String! @dgraph(type: "f1")
   517        }
   518      errlist: [
   519        {"message": "Type X; Field f1: pred argument for @dgraph directive should
   520        not be empty.",
   521        "locations":[{"line":2, "column":16}]}
   522        ]
   523  
   524    -
   525      name: "Dgraph directive with no argument on field produces an error"
   526      input: |
   527        type X {
   528          f1: String! @dgraph
   529        }
   530      errlist: [
   531        {"message": "Type X; Field f1: pred argument for @dgraph directive should
   532        not be empty.",
   533        "locations":[{"line":2, "column":16}]}
   534        ]
   535  
   536    -
   537      name: "Dgraph directive with wrong argument type on field produces an error"
   538      input: |
   539        type X {
   540          f1: String! @dgraph(pred: 2)
   541        }
   542      errlist: [
   543        {"message": "Type X; Field f1: pred argument for @dgraph directive should
   544        of type String.",
   545        "locations":[{"line":2, "column":16}]}
   546        ]
   547  
   548    -
   549      name: "Dgraph directive with wrong argument on type produces an error"
   550      input: |
   551        type X @dgraph(pred: "X") {
   552          f1: String!
   553        }
   554      errlist: [
   555        {"message": "Type X; type argument for @dgraph directive should not be empty.",
   556        "locations":[{"line":1, "column":9}]}
   557      ]
   558  
   559    -
   560      name: "Dgraph directive with no argument on type produces an error"
   561      input: |
   562        type X @dgraph {
   563          f1: String!
   564        }
   565      errlist: [
   566        {"message": "Type X; type argument for @dgraph directive should not be empty.",
   567        "locations":[{"line":1, "column":9}]}
   568      ]
   569  
   570    -
   571      name: "Dgraph directive with wrong argument type on type produces an error"
   572      input: |
   573        type X @dgraph(type: 2) {
   574          f1: String!
   575        }
   576      errlist: [
   577        {"message": "Type X; type argument for @dgraph directive should of type String.",
   578        "locations":[{"line":1, "column":9}]}
   579      ]
   580  
   581  
   582  valid_schemas:
   583    -
   584      name: "hasInverse directive on singleton"
   585      input: |
   586        type X {
   587          f1: Y @hasInverse(field: "f1")
   588        }
   589        type Y {
   590          f1: X @hasInverse(field: "f1")
   591        }
   592  
   593    -
   594      name: "hasInverse directive on list type 1"
   595      input: |
   596        type X {
   597          f1: [Y] @hasInverse(field: "f1")
   598        }
   599        type Y {
   600          f1: X @hasInverse(field: "f1")
   601        }
   602  
   603    -
   604      name: "hasInverse directive from list type"
   605      input: |
   606        type Post {
   607          postId: ID!
   608          author: Author!
   609        }
   610  
   611        type Author {
   612          posts: [Post!]! @hasInverse(field: "author")
   613        }
   614    -
   615      name: "hasInverse directive to list type"
   616      input: |
   617        type Post {
   618          postId: ID!
   619          author: Author! @hasInverse(field: "posts")
   620        }
   621  
   622        type Author {
   623          posts: [Post!]!
   624        }
   625  
   626    -
   627      name: "hasInverse directive on list type 2"
   628      input: |
   629        type X {
   630          f1: [Y] @hasInverse(field: "f1")
   631        }
   632        type Y {
   633          f1: [X] @hasInverse(field: "f1")
   634        }
   635  
   636    -
   637      name: "Correct search types"
   638      input: |
   639        type X {
   640          int1: Int @search
   641          int2: Int @search(by: [int])
   642          int3: Int @search(by: [])
   643          float1: Float @search
   644          float2: Float @search(by: [float])
   645          float3: Float @search(by: [])
   646          bool1: Boolean @search
   647          bool2: Boolean @search(by: [bool])
   648          bool3: Boolean @search(by: [])
   649          str: String @search
   650          str2: String @search(by: [])
   651          strHash: String @search(by: [hash])
   652          strExact: String @search(by: [exact])
   653          strTerm: String @search(by: [term])
   654          strFulltext: String @search(by: [fulltext])
   655          strTrigram: String @search(by: [trigram])
   656          strRegexp: String @search(by: [regexp])
   657          strRegexpFulltext: String @search(by: [regexp, fulltext])
   658          strMultipleIndex: String @search(by: [trigram, hash, term, fulltext])
   659          dt: DateTime @search
   660          dt2: DateTime @search(by: [])
   661          dtYear: DateTime @search(by: [year])
   662          dtMonth: DateTime @search(by: [month])
   663          dtDay: DateTime @search(by: [day])
   664          dtHour: DateTime @search(by: [hour])
   665          enumFld: E @search
   666          req: String! @search(by: [term])
   667          list: [Int] @search
   668          reqList: [DateTime!]! @search
   669        }
   670        enum E {
   671          A
   672        }