Closed ramprasad2018 closed 5 years ago
Hi there,
From the look of it, your schema just contain types definition, but it doesn't have resolver to actually resolve your schema values.
And the error is because of the lack of the resolver. You'll need to provide to your schema a resolve function, that take in an object and returns either StudyGroup
or Workout
.
This lib will generate a type: type PossibleAgendaItemTypeNames = 'StudyGroup' | 'Workout'
, and a function called AgendaItemTypeResolver
, that will help to make resolver type-safe.
I hope this will help.
Close due to inactivity.
Hi, I have defined a Schema with union. However the resolved is throwing the following run time error:
I have attached the schema.js and index.js text. Please help me in rectifying the resolver of the union type.
schema.js
import { buildSchema } from 'graphql';
const schema = buildSchema(`
index.js
import express from 'express'; import graphqlHTTP from 'express-graphql'; import schema from './schema';
const app = express();
app.get('/', (req,res) => { res.send('Graph QL is amazing!'); });
// Custom Functions
function responseToQuery(obj){ return [ {"name": "Rudra"}, {"name": "Ram"} ] }
const root = { agenda: (obj) => responseToQuery(obj) };
app.use('/graphql', graphqlHTTP({ schema: schema, rootValue: root, graphiql: true, }));
app.listen(9090, () => console.log('Running server on port localhost:9090/graphql'));
ERROR
"errors": [ { "message": "Abstract type AgendaItem must resolve to an Object type at runtime for field Query.agenda with value { name: \"Rudra\" }, received \"undefined\". Either the AgendaItem type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",