Query.Product defined in resolvers, but not in schema

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.

  1. server.mjs
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});

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

You defined Product inside the Query Object in your resolver, you need move to outside
From:

const resolvers = {
  Query: {
    products: () => {/*code*/},
    Product: {
      inventory: () => {/*code*/}
    }
  }
}

To:

const resolvers = {
  Query: {
    products: () => {/*code*/},
  },
  Product: {
    inventory: () => {/*code*/}
  }
}