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

[Parser] Empty type condition is not being caught in parse #780

Closed
rishabh3112 opened this issue Dec 12, 2023 · 4 comments · Fixed by #781
Closed

[Parser] Empty type condition is not being caught in parse #780

rishabh3112 opened this issue Dec 12, 2023 · 4 comments · Fixed by #781
Assignees
Labels
bug Something isn't working triage

Comments

@rishabh3112
Copy link
Contributor

rishabh3112 commented Dec 12, 2023

Description

please see: https://astexplorer.net/#/gist/e743877f4e424459a91a0f17670b787e/e52d925b8851a0190cdae33e6a3d88f6282dbb71

The JS parser for graphql catches this error but is not currently caught by apollo_parser. The TypeCondition .named_type() gets resolved with None value.

P.S. for context in https://github.com/rishabh3112/graphql-tag-swc-plugin, I am updating parser from v0.2.10 to latest. earlier this was caught in parse, but now this is not being caught.

Steps to reproduce

run parser with following input:

fragment PictureFragment on {
  uri
}

query testQuery {
  getData {
      ... on {
           id
        }
  }
}

For both no errors are there.

Expected result

Should be present in parse errors

Actual result

No errors

Environment

  • Operating system and version:
  • Shell (bash/zsh/powershell):
  • apollo-rs crate:
  • Crate version: apollo_parser: 0.7.4
@rishabh3112 rishabh3112 added bug Something isn't working triage labels Dec 12, 2023
@rishabh3112
Copy link
Contributor Author

I am happy to contribute this here! (if this issue is unexpected). Please point to me where should I look for this 😅

@SimonSapin
Copy link
Contributor

This does look like a bug! If you’re interested in working on it, start by creating a crates/apollo-parser/test_data/parser/err/0053_on_without_type_condition.graphql file (assuming 0052 is still the last existing one when you do it) with the test input. I’ve simplified it a bit:

query {
  ... on {
    field
  }
}

fragment F on {
  field
}

Now run UPDATE_EXPECT=1 cargo test -p apollo-parser --lib parser_tests and check that the test fails with a "There should be errors" message.

Next modify the parser code in crates/apollo-parser/src/parser/grammar/fragment.rs (maybe adding some calls to p.err) until instead of that message the test creates a .txt file with two ERROR lines pointing at the inline fragment and at the fragment spread.

Once satisfied run the whole test suite with cargo test to make sure nothing else is broken, and cargo fmt && cargo clippy --all-targets to prepare a PR.

@SimonSapin
Copy link
Contributor

Thank you for the report and test case!

@rishabh3112
Copy link
Contributor Author

@SimonSapin thanks for the help! will start on this and raise the PR for the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants