Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use embed for all graphql files sources #2198

Open
frederikhors opened this issue May 24, 2022 · 4 comments
Open

Use embed for all graphql files sources #2198

frederikhors opened this issue May 24, 2022 · 4 comments

Comments

@frederikhors
Copy link
Collaborator

frederikhors commented May 24, 2022

@vikstrous Now that I have tried to solve #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...
@vikstrous
Copy link
Contributor

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.

@clayne11
Copy link
Contributor

clayne11 commented Jun 30, 2022

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.

@frederikhors
Copy link
Collaborator Author

Can you PR please?

@clayne11
Copy link
Contributor

clayne11 commented Jul 7, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants