Getting error deploying to Vercel : `Error: "Query" defined in resolvers, but not in schema`
azerpas opened this issue · 6 comments
I'm trying to deploy a slightly modified version of the Next.js official graphql-let example and I'm getting this error Error: "Query" defined in resolvers, but not in schema
.
So I've looked into lib/schema.ts
and when adding some logs:
import { join } from 'path'
import { makeExecutableSchema } from '@graphql-tools/schema'
import { loadFilesSync } from '@graphql-tools/load-files'
import { mergeTypeDefs } from '@graphql-tools/merge'
import graphQLLetConfig from '../../.graphql-let.yml'
import resolvers from './resolvers'
const loadedFiles = loadFilesSync(join(process.cwd(), graphQLLetConfig.schema))
const typeDefs = mergeTypeDefs(loadedFiles)
console.log(`Loaded files:`);
console.log(loadedFiles);
console.log(`Graphql-let config schema`);
console.log(graphQLLetConfig.schema);
console.log(`Path ${process.cwd()}`);
console.log(`Join: ${join(process.cwd(), graphQLLetConfig.schema)}`)
export const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
I'm getting this:
Loaded files:
[]
Graphql-let config schema
**/*.graphqls
Path /var/task
Join: /var/task/**/*.graphqls
Loaded files seems to be empty. An issue was opened last year #214 regarding this error with SSR config but I'm running a Static config.
loadFileSync
requires the files to be present on the Vercel filesystem at runtime. By default Vercel will only include the built files. You need to update your Vercel configuration to tell it to include these files.
The other option is not to use loadFileSync and instead use Webpack to load the files at build time. This way they are included in the built output
import { join } from 'path'
import { makeExecutableSchema } from '@graphql-tools/schema'
import { loadFilesSync } from '@graphql-tools/load-files'
import { mergeTypeDefs } from '@graphql-tools/merge'
import graphQLLetConfig from '../../.graphql-let.yml'
import resolvers from './resolvers'
import schema1 from "./schema1.graphqls"
import schema2 from "./schema2.graphqls"
const typeDefs = mergeTypeDefs([
schema1,
schema2
])
export const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
Thanks @marklawlor, I will try this. Closing for now!
@marklawlor you saved my day, Thanks.
Just for more clarification as it takes a while for me if you are going to use the workaround option which is importing the files directly you need to download another loader like webpack-graphql-loader
and add it to the next.config.js
like this:
config.module.rules.push({
test: /\.graphqls$/,
exclude: /node_modules/,
use: ['webpack-graphql-loader'],
});
That fixes the issue for me after a long investigation, good luck
@medhatdawoud You can use graphql-let/schema/loader
as your loader as well.
@medhatdawoud You can use
graphql-let/schema/loader
as your loader as well.
@marklawlor graphql-let/schema/loader
gives me the following error:
error - ./src/lib/graphql/schema.graphqls
Module parse failed: The keyword 'enum' is reserved (1:0)
File was processed with these loaders:
* ../../node_modules/.pnpm/graphql-let@0.18.6_db90a9da515a41f30be6826adac119a7/node_modules/graphql-let/schema/loader.js
You may need an additional loader to handle the result of these loaders.
If I use webpack-graphql-loader
instead it works fine.
I would create a new issue for that and include a reproduce-able demo.