gqlgen
gqlgen copied to clipboard
Use embed for all graphql files sources
@vikstrous Now that I have tried to solve https://github.com/99designs/gqlgen/issues/2196 by myself I have realized that you are only using embed for the first file in the list of possible graphql files of the config schema
field.
Can you try adding another in your project (maybe even using the glob way) and check that it's not just me?
Like my one:
schema:
- schema/*.graphql
- ../../pkg/**/gqlgen/schema/*.graphql
Just as an example, this is an exceprt of the generated.go file after your improvement:
var sources = []*ast.Source{
{Name: "schema/schema.graphql", Input: sourceData("schema/schema.graphql"), BuiltIn: false},
{Name: "../../pkg/player/gqlgen/schema/player.graphql", Input: `type Player {
id: ID!
createdAt: Time!
name: String!
age: Int!
}
`, BuiltIn: false},
// and so on many other sources here...
Unfortunately, not all files can be embedded because "embed" doesn't allow embedding files that are not in the package's directory or subdirectories. There's nothing we can do about that. I recommend trying to move the graphql schema files to the same directory as the generated code.
We should be able to set up embed
to be used if you call api.Generate
programmatically which is easy to do.
It would be similar to what I did in #2262.
Can you PR please?
After looking more closely I didn't exactly understand what we were trying to do. I thought this was about the generation step, not the serving step. As @vikstrous said there's no way to do this unless the schema files are in the same directory, at which point they're already being embedded.
In terms of the Generate
API, it's already taking in parsed schema files, so there's no place to use go:embed
here - the API callers can already do that in their own code.