-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Emit raw query text in artifact for @relay_test_operation
operations
#4999
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
Conversation
Hi @jakobkhansen! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
TODO: Write a test where rawText is not |
I'm curious how is the text used for test operations?
Apart from client extensions, is there anything else that is missing in Since the raw text is intended for |
@tyao1 our main use case right now is to include the client extensions, yes. What type of flag were you thinking here? Since this would need to be on a per operation basis, would it be a directive similar to To answer the question on how Good tip on the directive to store the data, if we don't go the flag route I will look into that change. |
That's correct.
|
I've been trying to do the flag route and skip the client extensions transform, and I have some questions. We cannot skip the transform entirely, since of course we have multiple operations in a program and some may not have But then comes the issue that the transform also deletes fragments that are What do you think @tyao1? |
Ok, so I attempted the flag to not do the query TestOperation @relay_test_operation(includeClientExtensions: true) {
...ServerType
}
query ServerOperation {
...ServerType
}
fragment ServerType {
serverField
clientExtension
} Since the test operation uses the The only thing we could do would be to duplicate the fragment somehow and have a separate version which keeps the client extensions, but I think this would be a bit complicated and probably we don't want to do that. I think the best option is to as you suggested, have an argument on I pushed this change now, which adds the @tyao1 , please have a look and see if this approach is viable :) |
Makes sense. Thanks for trying out this approach |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very clean! Requesting changes to check EMIT_RAW_TEXT_ARG
before attaching the raw text
Thanks for the review @tyao1, let me know if there is anything else to fix now :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! It would be nice to have a snapshot test for the raw text generation under relay-compiler/tests/compile_relay_artifacts/fixtures
, but it is up to you.
@tyao1 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@tyao1 I added a test and hopefully fixed the lint issue that was failing on CI. |
@tyao1 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@tyao1 sorry for the back and forth, I had manually updated the fixture tests before as I was unaware of |
@tyao1 ping on this one :) |
@tyao1 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@jakobkhansen I brought the PR up to the team, and we have more questions. Using raw query text has the downside that some client only directives like @required will no longer work. Could you provide more detail on how the generated payload is consumed? |
Sure, we are planning on using it exactly here. The idea is that we have a Storybook decorator which should work to generate mock-data for both Apollo and Relay based applications, and uses the Graphitation payload-generator. What we do for Relay operations is take the If there are concerns with this breaking the |
Chiming in to support the request for features like this. At Atlassian, we also had to tweak the compiler to output the query text (a bit of a hack - into the extra artifacts dir) so that our tests can look that up and mock it. We've been carrying that patch across upstream updates for a while now. We'd additionally like to shift from this setup to instead actually hit a local server. Sending 1k+ queries over the network and the resolvers for storybook takes a while to bundle since GraphQL is a natural "barrelling" point. But even that would then have the same trouble: the query text for these operations doesn't even exist in our repo (they're persisted to a service), so any mechanism to get the query text out is valuable: Even something as simple as allowing the |
@tyao1 I'm not sure I understand why Am I misunderstanding that this would only change the query string that is in the Perhaps because these fields would now returned in the payload from the mock server even though they're actually client extensions? But I think |
Hello!
In Microsoft we have a use case where we would like to parse Relay operations being executed with
graphql-js
. In our case this is specifically for testing with Storybook, where we want to use Graphitation payload generator to generate mock data, which takesgraphql-js
operations as input.Today, parsing operations is somewhat limited because the
text
field in Relay operation artifacts is heavily transformed and for example does not contain client extensions. We would like to expose the raw, untransformed query text in operation artifacts, hidden behind the@relay_test_operation
directive. We believe this would be useful in other testing scenarios as well, because it enables Relay operations to be easily converted between formats and used with other GraphQL tooling.This PR implements that by adding a
rawText
field inOperationDefinition
and a new transform, theRawTextTransform
. The transform populates this field, only on operations with@relay_test_operation
directive. The transform is specifically added as the first transform to be executed, since it relies on generating the original, "raw" query text, before any other transforms are applied.Here's an example on how
rawText
would be exposed in an artifact:where you can see that
viewData
, which is a client-extension, is preserved.I've added this field also to Flow types, and if you think it makes sense to mention this in docs, I can add that as well.
Would love to hear if you have any thoughts on adding this feature :)