1

im new in graphql, and what i want to achieve is simplify this schema:

input UserQueryFilter {
   email: String
}
input UserQueryInput {
    filter: UserQueryFilter
    anotherArgs: String
}

type User {
   email: String!
}

Query { 
    User (input: UserQueryInput) : [User]
}

into this:


input UserQueryFilter {
   email: String
}

type User {
   email: String!
}

Query { 
    User (input: { filter: UserQueryFilter }, anotherArgs: String ) : [User]
}

but i got :

Syntax Error: Expected Name, found "{".","locations":[{"line":183,"column":20}] ...

when it comes to more complex application, it will become easier to code on the second one. is there anything can do about it?

Thanks for your help!

FatihAziz
  • 438
  • 4
  • 11

1 Answers1

1

The second schema is syntactically wrong. After a semicolon, always a Type will be expected. This type may be default types like String, ID, Int etc, or a custom type. Specifically for query params, it should be a default type or an Input type. Otherwise, as you mentioned, the buildSchema method will throw an error while parsing the entire schema.

Deepak Kumar
  • 154
  • 5
  • I see, so there is no way to simplify the syntax? because its very hassle to create specific type only for Object with 1 or 2 field. like the example. – FatihAziz Jan 14 '22 at 08:36
  • yes AFAIK. In fact, defining types using this GQL syntax is a simplified way compared to the other way of defining it. https://graphql.org/graphql-js/type/#examples – Deepak Kumar Jan 17 '22 at 04:52