You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [myPlugin],
});
const { url } = await startStandaloneServer(server);
console.log(🚀 Server ready at ${url});
`
This is the error it gives
amitnerkar@P3CLAP-1337639:~/apollo-server/packages/server$ node server.mjs
file:///home/amitnerkar/apollo-server/node_modules/@graphql-tools/schema/esm/addResolversToSchema.js:62
throw new Error(${typeName}.${fieldName} defined in resolvers, but not in schema);
^
Error: Query.Product defined in resolvers, but not in schema
at addResolversToSchema (file:///home/amitnerkar/apollo-server/node_modules/@graphql-tools/schema/esm/addResolversToSchema.js:62:35)
at makeExecutableSchema (file:///home/amitnerkar/apollo-server/node_modules/@graphql-tools/schema/esm/makeExecutableSchema.js:73:14)
at ApolloServer.constructSchema (file:///home/amitnerkar/apollo-server/packages/server/dist/esm/ApolloServer.js:301:16)
at new ApolloServer (file:///home/amitnerkar/apollo-server/packages/server/dist/esm/ApolloServer.js:68:49)
at file:///home/amitnerkar/apollo-server/packages/server/server.mjs:108:16
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to write a resolver and schema in apollo server. However while compiling it giving thie error
Query.Product defined in resolvers, but not in schema
i have this resolver file wherein the resolver and schema is defined as below.
`import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
// The GraphQL schema
const typeDefs =
#graphql type Product { id: String name: String inventory: [Inventory] } type Inventory { qty: Int } type Query { products: [Product] }
;// A map of functions which return data for the schema.
const resolvers = {
Query: {
products: async () => {
return fetch(
http://192.168.99.2:3000/products
, {method: "POST",
mode: "cors",
credentials: "include",
headers: {
"Content-Type": "application/json"
},
}).then(response => response.json())
.then((data) => console.log(data)) // Do something with the data
.catch((error) => console.error(error)) // Handle errors
},
Product: {
inventory: async (parent) => {
const { id } = parent
return fetch(
http://192.168.99.2:3000/products/${id}/inventory
, {method: "POST",
mode: "cors",
credentials: "include",
headers: {
"Content-Type": "application/json"
},
}).then(response => response.json())
.then((data) => console.log(data)) // Do something with the data
.catch((error) => console.error(error)) // Handle errors
},
},
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [myPlugin],
});
const { url } = await startStandaloneServer(server);
console.log(
🚀 Server ready at ${url}
);`
This is the error it gives
amitnerkar@P3CLAP-1337639:~/apollo-server/packages/server$ node server.mjs
file:///home/amitnerkar/apollo-server/node_modules/@graphql-tools/schema/esm/addResolversToSchema.js:62
throw new Error(
${typeName}.${fieldName} defined in resolvers, but not in schema
);^
Error: Query.Product defined in resolvers, but not in schema
at addResolversToSchema (file:///home/amitnerkar/apollo-server/node_modules/@graphql-tools/schema/esm/addResolversToSchema.js:62:35)
at makeExecutableSchema (file:///home/amitnerkar/apollo-server/node_modules/@graphql-tools/schema/esm/makeExecutableSchema.js:73:14)
at ApolloServer.constructSchema (file:///home/amitnerkar/apollo-server/packages/server/dist/esm/ApolloServer.js:301:16)
at new ApolloServer (file:///home/amitnerkar/apollo-server/packages/server/dist/esm/ApolloServer.js:68:49)
at file:///home/amitnerkar/apollo-server/packages/server/server.mjs:108:16
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Node.js v20.11.1
Beta Was this translation helpful? Give feedback.
All reactions