Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@edvinerikson
Copy link
Contributor

This fixes #3941 so that fetchable directive is usable in OSS.

Why is this needed?

fields starting with __ is reserved in the GraphQL spec and since this field isn't part of the spec any attempt of using the field on a server that is spec compliant will result in an error.

What changed?

  • Added a new opt-in enableTokenField config option.
  • Conditionally include the __token field in refetchable fragment selections based on the config option.

How has this been tested?

One could argue we should add a new test asserting the old behavior, I wasn't too sure how to go about adding a special fixture though.

The tests now assert that __token is not being generated.

cc @captbaritone

@captbaritone
Copy link
Contributor

Thanks for the quick PR! A few style suggestions. Other than that, my main concern is that we get this tested.

Let's ensure we have tests that cover both cases. You can change https://github.com/facebook/relay/blob/d5d1c07d7a44856f82c9a652697e9662a091d4c6/compiler/crates/relay-transforms/tests/refetchable_fragment/mod.rs#LL18C60-L18C67 to build a custom schema config and then use a pattern like this to make it conditional based on a comment in the fixture file.

Then please add tests which ensure we cover both cases.

Finally, does this introduce a possibility that a type would have neither a an id field or a token field? Do we have validation anywhere to catch that?

@edvinerikson
Copy link
Contributor Author

I'll look into adding tests for this using a flag like that, thanks for the pointers!

@edvinerikson
Copy link
Contributor Author

Finally, does this introduce a possibility that a type would have neither a an id field or a token field? Do we have validation anywhere to catch that?

We still fetch the id field if it exists. And we always fetch the fetchable id. As long as the type you add fetchable to has an id field we should be OK.But I suppose we could add validation for the scenario where tokenFieldEnabled: false and the type does not have the id field available.

@edmundgentle
Copy link

Is there a reason this PR hasn't been accepted yet? I'm running into this problem and without editing the generated files, I can't see another way around this until this PR is merged?

@captbaritone
Copy link
Contributor

Apologies for loosing track of this. Let me import/rebase this and play around with it a bit.

@facebook-github-bot
Copy link
Contributor

@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@captbaritone
Copy link
Contributor

Import failed due to this PR being old and our internal tool getting stuck when trying to rebase. I'm going to take these commits, rebase them myself and open a new PR to import. The author info on the commit should remain

@captbaritone
Copy link
Contributor

Rebased here: #4889 Going to close this PR. We can continue the conversation on that PR.

facebook-github-bot pushed a commit that referenced this pull request Jan 28, 2025
…#4347 (#4889)

Summary:
#4347

Pull Request resolved: #4889

Test Plan: Ran Relay compiler with this config change D68577067 and saw no generated artifact changes.

Reviewed By: lynnshaoyu

Differential Revision: D68569712

Pulled By: captbaritone

fbshipit-source-id: 42fdd4396963fe964a63c3736c236895b81ffde4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unknown field "__token" when using @fetchable

4 participants