Closed francoisromain closed 4 years ago
@francoisromain loadSchemaSync
already returns GraphQLSchema
so you don't need to call buildSchema
. You can just do;
import { buildSchema } from 'graphql'
import { loadSchemaSync } from '@graphql-tools/load'
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader'
import { join } from 'path'
const schema = loadSchemaSync(join(__dirname, 'schemas/index.graphql'), {
loaders: [new GraphQLFileLoader()],
})
export default schema
@ardatan thank you for your answer. Typescript does not make an error anymore.
now, there is an other error:
/dist/import/src/index.js:235
throw new Error(`Couldn't find type ${dependencyName} in any of the schemas.`);
^
Error: Couldn't find type Utilisateur in any of the schemas.
My schema is split in different files.
With graphql-import
, I was importing all the files into index.graphql
with comments like so:
# import * from 'administrations.graphql'
# import * from 'utilisateurs.graphql'
# etc.
What is the new way to do it?
Could you share a reproduction in a CodeSandbox project or a GitHub repo?
the error is caused by circular dependencies in graphql-tools
.
here is the repro and the description of the bug: https://github.com/francoisromain/graphql-tools-config-debug
thank you
@francoisromain It cannot find Enterprise
here because it is not imported;
https://github.com/francoisromain/graphql-tools-config-debug/blob/master/src/api/schemas/users.graphql#L5
So User
cannot be found in here as well;
https://github.com/francoisromain/graphql-tools-config-debug/blob/master/src/api/schemas/enterprises.graphql#L3
@ardatan thank you! I understand and don't have the import error anymore. but… I still have an error :sweat_smile:
This time I have 2 files: index.graphql
and territoires.graphql
.
index.graphql :
# import * from 'territoires.graphql'
type Query {
pays: [Pays]
}
territoires.graphql
type Departement {
id: ID!
}
type Region {
id: ID!
departements: [Departement]
}
type Pays {
id: ID!
regions: [Region]
}
The error is
/node_modules/graphql/validation/validate.js:108
throw new Error(errors.map(function (error) {
^
Error: Unknown type "Departement".
If I don't use a separate file and put everything in index.graphql
like so, there is no error:
type Query {
pays: [Pays]
}
type Departement {
id: ID!
}
type Region {
id: ID!
departements: [Departement]
}
type Pays {
id: ID!
regions: [Region]
}
What am I doing wrong?
@francoisromain Could you update your reproduction with your last scenerio? Thanks!
I updated the repo with this error: https://github.com/francoisromain/graphql-tools-config-debug :pray:
Hello @ardatan I see the issue is still marked as waiting for answer
. Can I do something more about it?
@francoisromain I removed the label. Working on it! Thanks for the reproduction :)
I re-opened the issue here: https://github.com/ardatan/graphql-tools/issues/1782
Hello,
I have seen the migration instructions to graphql-tools, but my config is a bit different.
currently I have
I tried
But there is a typescript error
What is the correct way to do it?
Thank you