GraphQL use simple object instead create specific type on schema

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!

1 answer

  • answered 2022-01-13 09:39 Deepak Kumar

    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.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum