Closed mariogarcia closed 6 years ago
Having an schema with an interface and several implementations:
interface Raffle { id: String title: String names: [String] } type SimpleRaffle implements Raffle { id: String title: String names: [String] owner: String } type TwitterRaffle implements Raffle { id: String title: String hashTag: String names: [String] } type Queries { raffles(max: Int): [Raffle] } schema { query: Queries }
We should be able to execute a query like this:
{ raffles(max: 2) { title ... on TwitterRaffle { hashTag } } }
A possible DSL implementation should look like:
GraphQLSchema proxySchema = DSL.mergeSchemas { byResource('gql/dsl/typeresolver.graphqls') { mapType('Queries') { link('raffles') { return [[title: 'T-Shirt', hashTag: '#greachconf']] } } mapType('Raffle') { typeResolver { TypeResolutionEnvironment env -> def raffle = env.getObject() as Map def schema = env.schema return raffle.containsKey('hashTag') ? schema.getObjectType('TwitterRaffle') : schema.getObjectType('SimpleRaffle') } } } }
The method typeResolver should provide two different options:
typeResolver
typeResolver(Closure typeResolver) or typeResolver(TypeResolver typeResolver)
typeResolver(Closure typeResolver)
typeResolver(TypeResolver typeResolver)
Having an schema with an interface and several implementations:
We should be able to execute a query like this:
A possible DSL implementation should look like:
The method
typeResolver
should provide two different options:typeResolver(Closure typeResolver)
ortypeResolver(TypeResolver typeResolver)