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

GraphQLInteraction doesn't support named queries #235

Closed
sh3pik opened this issue Oct 25, 2018 · 6 comments
Closed

GraphQLInteraction doesn't support named queries #235

sh3pik opened this issue Oct 25, 2018 · 6 comments

Comments

@sh3pik
Copy link

sh3pik commented Oct 25, 2018

Apollo allows naming operations for a query or a mutation. It can be specified right after a keyword, e.g. query, and goes to operationName in the body of the request

A valid request must contain either a query or an operationName (or both, in case of a named query)

query HomeBookListing {
  getBooks {
    title
  }
}
{
  "body": {
    "query": "query HomeBookListing { getBooks { title } }",
    "operationName": "HomeBookListing"
  }
}

Expected behaviour

I expect .withOperation() to work with named operations.

Actual behaviour

.withOperation() allows only query or mutation:

You must provide a valid HTTP method: query, mutation.
@mefellows
Copy link
Member

Thanks @sh3pik, it makes sense to support this.

Can you please show me exactly what you'd like the DSL to look like and also what you've tried?

@sh3pik
Copy link
Author

sh3pik commented Oct 26, 2018

I expect to be able to do something like:

new GraphQLInteraction()
.withOperation('HomeBookListing')
.withQuery('query HomeBookListing { getBooks { title } }')

If I run it on the current version, I'll get the error You must provide a valid HTTP method: query, mutation.
I tried without .withOperation('HomeBookListing'), I saw the error No matching interaction found in logs:

Diff
--------------------------------------
Key: - is expected 
     + is actual 
Matching keys and values are not shown

 {
   "body": {
-    "operationName": null
+    "operationName": "HomeBookListing"
   }
 }

Description of differences
--------------------------------------
* Expected nil but got "HomeBookListing" at $.body.operationName

@mefellows mefellows removed the Triage label Oct 27, 2018
@mefellows
Copy link
Member

Thanks @sh3pik, having another look at the docs I think we are just being a little bit too strict on what the withOperation takes - it's really up to the user. I'll remove the restriction and error message for that field.

@mefellows
Copy link
Member

I've pushed out a new release with a fix (16df628), let us know how you go!

@sh3pik
Copy link
Author

sh3pik commented Oct 27, 2018

The fix works perfectly! Thanks a lot for a quick response!

@mefellows
Copy link
Member

mefellows commented Oct 27, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants