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

On main, there is no error if the schema file cannot be found #146

Closed
johnmaguire opened this issue Oct 27, 2021 · 1 comment · Fixed by #173
Closed

On main, there is no error if the schema file cannot be found #146

johnmaguire opened this issue Oct 27, 2021 · 1 comment · Fixed by #173
Labels
bug Something isn't working good first issue Good for newcomers help wanted Issues that anyone could pick up and implement if useful to them

Comments

@johnmaguire
Copy link
Contributor

Describe the bug
In v0.3.0 if you point to a schema file that does not exist you will be given an error:

unreadable schema file graph/schema.graphql: open graph/schema.graphql: no such file or directory

Past v0.3.0, you get a confusing error that the types are not known:

graph/genqlient.graphql:35: query-spec does not match schema: Unknown type "ActionInput".

To Reproduce

  1. genqlient.yaml contains a schema path that does not exist: schema: graph/nonexistent.graphqls
  2. Create an operations file that references types defined in the schema
  3. Run go run github.com/Khan/genqlient

Expected behavior

unreadable schema file graph/schema.graphql: open graph/schema.graphql: no such file or directory

genqlient version
v0.3.1-0.20211022224026-a4aa6d9bb0f4

The problem cannot be reproduced on v0.3.0.

Additional context
I believe the behavior was introduced in this commit: 59b6df6

Since we are globbing, we end up with an empty list of files to iterate. Since we don't try to load any files, we never return an error that they can't be loaded.

I'm not sure the best fix here - perhaps try to detect if a line is a glob or not, and only call the glob function if it is? Or maybe a glob pattern that returns no results should result in an error - or warning.

@johnmaguire johnmaguire added the bug Something isn't working label Oct 27, 2021
@benjaminjkraft
Copy link
Collaborator

Ah, good find. We should just check explicitly that we got at least one schema, e.g. that there's at least one type defined, or at least one filename. As you point out, there's some question as to whether we should require each glob match at least one file as well, I'd lean towards yes, especially since it sounds from your description like we do that even if there is no real glob.

@benjaminjkraft benjaminjkraft added help wanted Issues that anyone could pick up and implement if useful to them good first issue Good for newcomers labels Oct 27, 2021
benjaminjkraft added a commit that referenced this issue Feb 10, 2022
The most important case here is if your glob isn't even a glob, it's
just a filename.  But even if it was a glob, it's probably a mistake;
you'll probably end up with a confusing error due to an empty schema, or
a slightly less confusing error due to not having any operations.
Instead, let's just say outright that your glob didn't match any files.

Fixes #146.

Test plan:
This was a bit annoying to test via snapshot, so I just tested it
manually by modifying the example to use a glob that didn't match any
files, first for the schema then for the operations, and got errors like
```
bogus*.graphql did not match any files
exit status 1
example/main.go:68: running "go": exit status 1
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Issues that anyone could pick up and implement if useful to them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants