Gerrol
Gerrol

Reputation: 35

GraphQL schema definition - Can encapsulate object in a Input/Type?

Can I encapsulate object in an Input/Type? Assuming that we have this schema definition :

input MyChildInput {
  territoryId: String!
  mapsTo: [String!]!
}

input MyInput {
  uuid: ID!
  childInput: [MyChildInput!]!
}

I would like to have something like the code bellow, is it even possible ?

input MyInput {
  uuid: ID!
  childInput: [{
    territoryId: String!
    mapsTo: [String!]!
  }!]!
}

Upvotes: 0

Views: 70

Answers (1)

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40909

GraphlQL does not support anonymous types. All object types in GraphQL need to have a name.

Having named types has a lot of benefits. It allows type reuse, it also makes it possible to apply fragments against them. Type names are also used by various GraphQL clients to cache data fetched from the API.

Upvotes: 1

Related Questions