简体   繁体   中英

GraphQL typedef mutation need to accept an Array

How can I pass an array of custom type in a mutation when declaring typeDefs in GraphQL?

 type Itinerary { name: String! itinerary: [Location]! } input Location { name: String! country: String region: String city: String duration: Int! } type Mutation { addItinerary( name: String!, itinerary: [Location]!, ): Itinerary } 

I get the error in graphiql "The type of Itinerary.itinerary must be Output Type but got: [Location]!"

It seems to be such a trivial task but I could not find anything specific to this case

You're returning a type of Itinerary , which itself contains a nested Location , however you've stated that Location is an input type , which can't be returned as the result of a mutation. You need to define separate input types and can't return them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM