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

Cannot combine rest w/ graphql in the same query #97

Closed
chimon2000 opened this issue Apr 4, 2018 · 9 comments · Fixed by #138
Closed

Cannot combine rest w/ graphql in the same query #97

chimon2000 opened this issue Apr 4, 2018 · 9 comments · Fixed by #138
Labels
blocking Prevents production or dev due to perf, bug, build error, etc.. bug 🐛 has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository help wanted 🛠

Comments

@chimon2000
Copy link

chimon2000 commented Apr 4, 2018

Summary

I am attempting to intermingle a rest request with a graphql request. Both requests refer to the same resource and work when executed individually. However, when attempting to execute the two together

const QUERY_AUTHORS_AND_PEOPLE = gql`
    query {
        people @rest(type: "[Person]", path: "authors/") {
            firstName
        }

        authors {
            id
            firstName
        }
    }

I get the following error

image

You can find the example that I am referring to here

@ghost ghost added the blocking Prevents production or dev due to perf, bug, build error, etc.. label Apr 4, 2018
@fbartho
Copy link
Collaborator

fbartho commented Apr 4, 2018

Hey @chimon2000 -- this sounds like a big bug, do you feel comfortable submitting a unit-test for us that could reproduce this?

Alternately, a PR that fixes this would be even better. I'm happy to help, but my current main test environment doesn't use a real GraphQL server, so I'm not quite set up to verify that this is working.

@chimon2000
Copy link
Author

Hey @fbartho, thanks for the quick response. I added my example repo that contains the code necessary to reproduce the issue with both angular and (p)react examples, but I can see about adding a unit test for this as well.

I am not particularly adept with how apollo links work.

@fbartho fbartho added has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository help wanted 🛠 labels May 7, 2018
ivank added a commit to ivank/apollo-link-rest that referenced this issue Aug 6, 2018
ivank added a commit to ivank/apollo-link-rest that referenced this issue Aug 6, 2018
@ivank
Copy link
Contributor

ivank commented Aug 6, 2018

Hey @fbartho, I've added a PR failing test for you guys to poke around - it is indeed a problem, hope its useful.

ivank added a commit to ivank/apollo-link-rest that referenced this issue Aug 6, 2018
A test for apollographql#97

Alos added the
```
"testURL": "http://localhost/",
```
to jest config to allow tests to run
@paulpdaniels
Copy link
Contributor

Looking into the source it seems like the only time that forward is called to send the operation to the next link is here.

I think if we want to support the merging behavior we need to inspect the query strip out non-rest pieces and forward them to the next link.

I think basically copying this section from apollo-link-state would be sufficient (it might even make sense to coordinate with the maintainers to extract that kind of logic into a separate package since it seems really useful for link builders).

@paulpdaniels
Copy link
Contributor

paulpdaniels commented Aug 21, 2018

Actually I just checked and it is already part of apollo-utilities. @fbartho I'd be willing to take this on if no one else is already working on it. Seems like a relatively easy fix. Will need to imagine some various test scenarios though...

@fbartho
Copy link
Collaborator

fbartho commented Aug 21, 2018

@paulpdaniels Dude, I'd love that. Please do take it on.

Specific hazardous scenarios I want to make sure we support / don't break:

  • Nesting @rest() inside @rest() queries with `@export(as:…) in use
  • Nesting @rest() inside server-graphql queries with `@export(as:…) in use
  • Nesting @rest() inside @client queries
  • Making sure this doesn't break the Typename Patcher codepaths!

@marcelombc
Copy link

export directive doesn't seem to work inside server-graphql queries. I get the following error: Unknown directive "export".

@paulpdaniels
Copy link
Contributor

@marcelombc it would depend on your server implementation I guess, apollo-server comes with it out of the box, but I don't think it is required to be spec compliant.

@marcelombc
Copy link

@paulpdaniels You're right. I'm using graphene on the server and I just needed to create a custom directive to support @export. Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking Prevents production or dev due to perf, bug, build error, etc.. bug 🐛 has-reproduction ❤ Has a reproduction in a codesandbox or single minimal repository help wanted 🛠
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants