Apollo-link-rest: Cannot combine rest w/ graphql in the same query

Created on 4 Apr 2018  ·  9Comments  ·  Source: apollographql/apollo-link-rest

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

blocking bug 🐛 has-reproduction help wanted 🛠

Most helpful comment

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...

All 9 comments

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.

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.

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

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).

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...

@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!

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

@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.

@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.

Was this page helpful?
0 / 5 - 0 ratings