-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
"variables" are empty #709
Comments
Great question! This is intended - scalar values are printed inline, while input objects and enums are printed and sent as variables. This is somewhat of an arbitrary choice, though we have found that it's easier to debug queries with unlined argument values. |
@josephsavona, is it possible to change this behavior? |
Possible, yes, but what's the use case? As I said, the current approach has made queries easy to read and debug. |
@josephsavona I need these values before data resolving in schema. |
Ah, if I understand correctly you're trying to access the argument values at each |
@josephsavona no, I need it outside of GraphQL pipeline, before it reaches it, in a middleware. The thing is that I use dynamically generated schemas for some forms and based on root query I need to define which schema I should use for particular request. |
I see - thanks for clarifying your use case. While changing the way queries are printed may work this is a brittle approach as we may change the format at any point. Instead, it sounds like this is ultimately a problem of identifying (on the server) the schema that the client is using. The general solution in Relay to transmitting extra information between client and server is to use a custom network layer. With this approach, you can send the printed query (regardless of inclined variables or not) along with whatever metadata you need to identify the schema being used. |
@josephsavona custom NetworkLayer is not an option, because during single session there might different forms which require different GraphQL schemas. |
Hmm. A custom network layer does seem like the right approach here, but we'd need more information to give suggestions about implementing it:
The gist of these questions is that Relay requires the schema for a file to be known statically in order to transform it. Given that the schema is known statically per file, it should be possible to use that mapping in a custom network layer. |
@josephsavona let me explain what app does. Renderer is supposed to render form based on this definition. |
Thanks again for clarifying. As I mentioned above, relying on how Relay formats queries is a brittle approach that we don't recommend. Further, we'd prefer to avoid adding constraints on the formatting just to satisfy one product - this would limit our ability to iterate to possibly make improvements that benefit all users. That said, my original suggestion seems to apply: the supported approach here is to use a custom network layer. Since your top level root container fetched the form, it must know to what schema that belongs. It can then inform your network layer what schema to use for the inner query. An alternative implementation of a custom network layer is to access the query representation itself (via |
@ziflex I'm going to close this since it isn't a bug or enhancement. Feel free to ask follow-up questions here, or even better on stack overflow or in the discord channel. |
@josephsavona ok, thanks for help! |
Object, which is sent to the server, has a
variables
property.Accordingly to GraphQL spec it should contain query's variables.
But it turned out that Relay compiles the query and inserts variables inside of it.
Is it bug or feature? With current implementation it's almost impossible to use these values outside of GraphQL.
The text was updated successfully, but these errors were encountered: