operationName for Apollo Federation Gateway #595#596
operationName for Apollo Federation Gateway #595#596SammoMichael wants to merge 4 commits intoJetBrains:masterfrom
Conversation
Added operationName key to dynamically add query, mutation, or subscription name to data object or anonymous in unnamed next is to make the key editable to user/opt-in
|
|
||
| final String requestJson = "{\"query\":\"" + StringEscapeUtils.escapeJavaScript(query) + "\"}"; | ||
| final String requestJson = "{\"operationName\": \"IntrospectionQuery\", \"query\":\"" + StringEscapeUtils.escapeJavaScript(query) + "\"}"; | ||
| HttpPost request = createRequest(endpoint, url, requestJson); |
There was a problem hiding this comment.
This key "operationName" is required by my graphQLServer, was thinking could be made more generic by setting the keyname in .graphqlconfig maybe?
There was a problem hiding this comment.
Ended up putting textfield in GraphQL settings file for that
|
|
||
| Map<String, Object> requestData = new HashMap<>(); | ||
| requestData.put("query", context.query); | ||
| Pattern pattern = Pattern.compile("(query|mutation|subscription) (.*) ", Pattern.CASE_INSENSITIVE); |
There was a problem hiding this comment.
basically this allows regex to find the name of query to be added to operationName key in data object, if no name is detected, "anonymous" is added to query and operationName key as a workaround since our graphql server wouldn't allow truly nameless queries
| Everything should be working as intended, let me know what you think if you get a chance, thanks! @vepanimas |
| final String requestJson = "{\"operationName\": \"IntrospectionQuery\", \"query\":\"" + StringEscapeUtils.escapeJavaScript(query) + "\"}"; | ||
| HttpPost request = createRequest(endpoint, url, requestJson); | ||
| HttpPost request; | ||
| if (graphQLSettings.isOperationNameEnabled()) { |
There was a problem hiding this comment.
if setting is enabled, we check the keyname user wants in graphql settings or default to "operationName" then use default operation name value "IntrospectionQuery" since that would be appropriate value in most cases
{"operationName": "IntrospectionQuery", "query": {}}
There was a problem hiding this comment.
Can also make this dynamic like the normal request if there is a use case, can't think of one unless the graphql server is configured to only accept Introspection Query with a specific operation name
| } | ||
| } | ||
|
|
||
| private void handleOperationName(GraphQLSettings graphQLSettings, GraphQLQueryContext context, Map<String, Object> requestData) { |
There was a problem hiding this comment.
extracted to helper method, which handles getting the configured keyname for the operation name, and putting the correct value (either query|mutation|subscription name or "anonymous")
| } | ||
|
|
||
| final boolean reformatJson = contentType != null && contentType.getValue() != null && contentType.getValue().startsWith("application/json"); | ||
| final boolean reformatJson = contentType != null && contentType.getValue() != null && contentType.getValue().startsWith( |
There was a problem hiding this comment.
this was autoformatting change, can roll back
e.g. query myQuery( by capturing first set of (alphanumeric/underscores) in-between keyword and first non-alphanumeric character
|
Another question I had was I am having trouble building my fork of the plugin for Android Studio, is there an easiest way to configure a build that will work with Android Studio ? I guess I need some more practice with plugin versioning, even having trouble with Intellij, keep getting hit with different incompatibility errors :( |

Because of the way some GraphQL Servers are setup, a operationName key is required in the data object
{ "operationName": "SomeQuery", "query": {}, "variables": {}}
Added operationName key to dynamically add query, mutation, or subscription name to data object or anonymous in unnamed using regex matchers to extract the correct name from query
also set up UI to make the data key/value editable to user/opt-in. Users can configure a different keyname if needed
not sure if there is already some way built-in to accomplish this, but wanted to setup at least for my company and maybe if generalizable could be useful for others