ardatan / graphql-import

Import & export definitions in GraphQL SDL
868 stars 56 forks source link

the order of the files give different results #565

Closed zvictor closed 3 years ago

zvictor commented 4 years ago

I am facing errors while using graphql-import that vary depending on how I am calling the importSchema function.

First, I created a directory with 3 files, all containing valid graphql schemas:

Then I tried calling importSchema in multiple ways, but all of them showed problems. For each of the following pointerOrPointers, these are the results I got:

I made a reproducible code showing the problem. Edit: a simpler reproducible has been created for this issue.

ardatan commented 4 years ago

Could you remove #import from the beginning of the file and try again?

zvictor commented 4 years ago

Removing # import gives me:

zvictor commented 4 years ago

I started writing a reproducible to what I thought was a different issue, but it seems after all to actually be the same one. So, here we have another but simpler reproducible of this issue: https://github.com/zvictor/graphql-import-issue-565

ardatan commented 4 years ago

Providing multiple sources has some bugs right now. Until we fix it, I recommend you to use single endpoint which is GraphQL Import's main strategy or use https://github.com/ardatan/graphql-toolkit#-file-loading-for-both-schema-and-resolvers for now because it seems you don't need import syntax at all.

zvictor commented 4 years ago

Unfortunately things are not that simple on my side. I am using your code inside a framework I am building, so it needs to be quite flexible 😕

As I am building something to work with faunadb's graphql api, I need to always append a file with generic types that already exist inside fauna but are not defined on the user's code.

You can see my implementation at

https://github.com/zvictor/faugra/blob/801ee9eab496aa74b7347e8bd3ca86432c0630ff/commands/push-schema.js#L35-L51

brandonchinn178 commented 4 years ago

FYI just manually doing this works for me

const typeDefsResult = loadTypedefsSync('**/*.graphql', {
  loaders: [new GraphQLFileLoader()],
})

const typeDefs = mergeTypeDefs(
  typeDefsResult.flatMap(({ document }) => (document ? [document] : [])),
)

new ApolloServer({ typeDefs, ... })

it might be something to do with the mergeTypeDefs options?

zvictor commented 3 years ago

migrating from @graphql-toolkit to @graphql-tools has solved the issue to me, plus a customisation on the graphql-loader.