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 query field "_service" on type "Query" #3419

Closed
Kwadz opened this issue Oct 17, 2019 · 12 comments
Closed

Cannot query field "_service" on type "Query" #3419

Kwadz opened this issue Oct 17, 2019 · 12 comments

Comments

@Kwadz
Copy link

Kwadz commented Oct 17, 2019

I'm using Apollo Federation to connect to a GraphQL server made with Drupal GraphQL.

So I configured the gateway:

const { ApolloServer } = require("apollo-server");
const { ApolloGateway } = require("@apollo/gateway");

const gateway = new ApolloGateway({
  serviceList: [
    { name: 'content', url: 'http://gims_content_nginx/content' }
  ]
});

(async () => {
  const { schema, executor } = await gateway.load();

  const server = new ApolloServer({ schema, executor });

  server.listen().then(({ url }) => {
    console.log(`🚀 Server ready at ${url}`);
  });
})();

But when I start the server I get:

{ message: 'Cannot query field "_service" on type "Query".',
  extensions: { category: 'graphql' },
  locations: [ { line: 1, column: 30 } ] } 0 [ { message: 'Cannot query field "_service" on type "Query".',
    extensions: { category: 'graphql' },
    locations: [ [Object] ] } ]
(node:1) UnhandledPromiseRejectionWarning: Error: Apollo Server requires either an existing schema, modules or typeDefs
    at ApolloServer.initSchema (/usr/src/app/node_modules/apollo-server-core/dist/ApolloServer.js:239:23)
    at new ApolloServerBase (/usr/src/app/node_modules/apollo-server-core/dist/ApolloServer.js:201:30)
    at new ApolloServer (/usr/src/app/node_modules/apollo-server-express/dist/ApolloServer.js:58:9)
    at new ApolloServer (/usr/src/app/node_modules/apollo-server/dist/index.js:23:9)
    at /usr/src/app/gateway.js:13:18
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@wmertens
Copy link
Contributor

I have the same problem. It looks like these are added by apollo-federation and apollo-gateway assumes they are always there.

If you're trying to forward to a third-party graphql, that won't work :(

@brandonwkipp
Copy link

brandonwkipp commented Oct 25, 2019

I find myself in the same situation, it would be nice if we didn't have to do this, especially since some of these 3rd party graphql services are behind walls we don't control :(

@wmertens
Copy link
Contributor

I wound up implementing it with the "deprecated" schema stitching. It turns out that there's nothing preventing you from doing that, except that the necessary helpers now live in graphq-tools.

All you're doing is creating a Link, using that to fetch and wrape the remote schema, turning it into a local schema, and then merging it with your or other schemas. As long as you don't need the "foreign key" functionality of federation, this should always work.

Therefore I think the docs should be updated to mention this.

@ztolley
Copy link

ztolley commented Nov 1, 2019

I had the same and it really defeats what I needed. I just want to setup a simple gateway to route requests and merge results and thought that is what gateway was for.

@wmertens Do you have any examples or good places to explain how to do the stitching?

@wmertens
Copy link
Contributor

wmertens commented Nov 2, 2019

@ztolley actually the documentation is still valid, and only needed some slight tweaks #3449

@ztolley
Copy link

ztolley commented Nov 2, 2019

I found an excellent article and created a proof of concept that works perfectly. So I'll stick with stitching for now until it's supported by Sangria, Graphene and all the other libraries, not just Apollo

@abernix
Copy link
Member

abernix commented Nov 5, 2019

The downstream services in a federated architecture must implement the federation specification.

Many GraphQL servers have already implemented the federated specification already, including graphql-java, Ariadne, WPGraphQL and Graphene (via graphene-federation). Others are discussing it, including Sangria, quite recently.

@wmertens
Copy link
Contributor

wmertens commented Nov 6, 2019

@abernix why can't the federation support be optional, and if it's missing the assumption is that all federation metadata is empty, so federation falls back to simple stitching?

@brandonwkipp
Copy link

brandonwkipp commented Nov 8, 2019

@Kwadz FWIW, I abandoned using Drupal/GraphQL in favor of wrapping the Drupal RestUI module with Apollo Rest DataSource. I also wrapped another 3rd party api with the same package, works much better for our team than mucking around in PHP 🤷‍♂

Apollo Rest Datasources can be wrapped with the "buildFederatedSchema" function from the Apollo Federation package, automatically configuring the federation specification for you.

@mwawrusch
Copy link

Running into this issue now with faunadb downstream. Very annoying.

@maurocolella
Copy link

For anyone still struggling with this, check out:
https://github.com/0xR/graphql-transform-federation

Which makes good use of graphl-tools for remote schemas to make it possible to seamlessly federate and augment schemas not designed for Apollo.

Your mileage might vary, but thanks to that project, I've been able to bring a complex remote schema on board of our federated graph. Took me just a couple of hours.

@luijar
Copy link

luijar commented Jun 10, 2022

FYI for anyone stumbling into this and trying to figure it out. That project is out of date and doesn't work with latest Apollo libraries. I'm going to try to take that and see if I can re-engineer it so that I can federate over an existing schema (which I can't change) with latest Apollo server + Gateway

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants