Example of recursion GraphQL query and schema
var {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLInterfaceType,
buildSchema,
} = require('graphql');
var hero = new GraphQLObjectType({
name: 'hero',
fields: () => ({
name: {
type: GraphQLString,
},
hero: {
type: hero,
}
}),
});
var query = new GraphQLObjectType({
name: 'query',
fields: {
hero: {
type: hero,
},
},
});
var schema = new GraphQLSchema({
query: query,
});
var resolvers = {};
resolvers.hero = {
name: () => 'abc',
};
resolvers.hero.hero = resolvers.hero;
await graphql(schema, `
{
hero {
name
hero {
name
hero {
name
hero {
name
}
}
}
}
}
`, resolvers).then()
no comments