Closed thomascaillier closed 3 months ago
@thomascaillier Interesting. Can you edit your issue to describe an example of the actual content of those .gql
files?
Do you have an example of this feature being supported by other tools and libraries? Creating our own templating engine for that asks the question of IDE support...
@bclozel issue updated 👍
I know IntelliJ doesn't need any import, it seems it analyze the whole folder.
The #import
syntax is supported by npm @graphql-tools
: https://the-guild.dev/graphql/tools/docs/schema-loading#using-import-expression
Thanks for the update @thomascaillier
We looked into this and came to the conclusion that graphql-tools/graphql-utilities are the only solutions out there for this, and they're not just about concatenating pieces of schema, but really a complete namespace and import system that parses the schema elements and allows to rename types on-the-fly (a bit like TypeScript imports). So this not only applies to testing, but also to schemas in general.
We don't think we can achieve simply this level of support as this is very much tied to the TypeScript/JavaScript ecosystem.
What we could do instead is the following: offer tester.fragmentName("fragment")
and tester.fragment("...")
that lets you point to fragments that will be prepended to the actual document. This would not parse the schema nor support any namespacing feature. This would also require each test to point to fragments, which would make maintenance a bit harder.
If we're looking into a more complete and general solution for this, I think this should be discussed at the level of the graphql-java project - we're using its SchemaParser#parse
and TypeDefinitionRegistry#merge
methods to parse several files and merge the definitions. I don't think they support any type of import
syntax nor any extension point like @graphql-tools
does, but this might be a good discussion to have. Can you maybe start a discussion there to get the team's opinion on this?
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
Problem
I have several mutations and queries that returns the same type, so I use a fragment to define and reuse it. \ I want to test those mutations and queries using a
GraphQlTester
(more precisely aHttpGraphQlTester
).Let's assume I have mutation A and mutation B that are both using a fragment in
fragment.graphql
:definitions.graphqls :
mutationA.graphql :
mutationB.graphql :
fragments.graphql :
When I run a test like this :
Solutions
The solutions I see are either support an import syntax (ex:
#import "fragments.sql"
) or taking the wholegraphql-test
folder as context