'Apollo Server GraphQLSchema,GraphQLObjectType resolver schema and data fetching method
I am using apollo server and am interested in using a resolver schema data fetching method. Looking at examples I have constructed a simple schema:
const restApiResponse = {
created: "1",
};
let PersonTC = composeWithJson("Person", restApiResponse);
const typeDefs = new GraphQLSchema({
query: new GraphQLObjectType({
name: "Query",
fields: {
person: {
type: PersonTC.getType(), // get GraphQL type from PersonTC
args: {
id: {
type: new GraphQLNonNull(GraphQLInt),
},
},
resolve: (_, args) =>
fetch(
`https://api.gofun.com/api/person?eventid=342136`,
{
credentials: "include",
headers: {
authorization:
"Bearer a token",
},
}
).then((r) => {
return restApiResponse[created];
}),
},
},
}),
});
I am able to export this within my schema (using makeExecutableSchema) for Apollo and the definition works just fine. I also bring in other resolvers with this (also in makeExecutableSchema) however the resolve that is part of the typeDefs doesn't appear to be recognized.
const schema = applyMiddleware(
makeExecutableSchema({
typeDefs,
resolvers,
}),
permissions
);
And here is the basic Apollo server details
const server = new ApolloServer({
schema,
context: ({ event, context }) => ({
headers: event.headers,
functionName: context.functionName,
event,
context,
models,
}),
playground: true,
tracing: false,
introspection: true,
});
Playground documents it just fine but running:
{ person(id: 1) { created } }
Essentially returns an empty result and clearly the resolver does not fire. Am I simply unable to pursue a "resolver schema and data fetching method" while also stitching in separate resolvers from other sources?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
