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

Apollo Federation not working #12884

Closed
mengqing opened this issue Mar 19, 2022 · 12 comments
Closed

Apollo Federation not working #12884

mengqing opened this issue Mar 19, 2022 · 12 comments
Labels
issue: bug Issue reporting a bug issue: discussion A general discussion issue severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: plugin:graphql Source is plugin/graphql package status: pending reproduction Waiting for free time to reproduce the issue, or more information

Comments

@mengqing
Copy link

Bug report

Describe the bug

After enabling federation option, Federation service definition is not being generated

Expected behavior

It should return the federation service definition

Screenshots

If applicable, add screenshots to help explain your problem.

Code snippets

// path: ./config/plugins.js

module.exports = {
  //
  graphql: {
    config: {
      endpoint: '/graphql',
      shadowCRUD: true,
      playgroundAlways: false,
      depthLimit: 7,
      amountLimit: 100,
      federation: true,
      apolloServer: {
        tracing: false,
      },
    },
  },
};
query __ApolloGetServiceDefinition__ {
  _service {
    sdl
  }
}
{
  "errors": [
    {
      "message": "Cannot query field \"_service\" on type \"Query\".",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "extensions": {
        "code": "GRAPHQL_VALIDATION_FAILED",
        "exception": {
          "stacktrace": [
            "GraphQLError: Cannot query field \"_service\" on type \"Query\"."
          ]
        }
      }
    }
  ]
}

System

  • Node.js version: v16.13.0
  • NPM version: 8.3.0
  • Strapi version: v4
  • Database: postgres
  • Operating system:

Additional context

Add any other context about the problem here.

@mengqing
Copy link
Author

It seems that this PR #6146 from v3 does not exist in v4. Does anyone know the reason for that?

@derrickmehaffy derrickmehaffy added issue: bug Issue reporting a bug issue: discussion A general discussion issue severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: plugin:graphql Source is plugin/graphql package status: pending reproduction Waiting for free time to reproduce the issue, or more information labels Apr 11, 2022
@derrickmehaffy derrickmehaffy added this to To be reviewed (Open) in Developer Experience - Old via automation Apr 11, 2022
@derrickmehaffy
Copy link
Member

@Convly I'm honestly not sure here, can you share any information. I only see that we have the apollo federation package installed but it's not referenced anywhere in the code-base:

"@apollo/federation": "^0.28.0",

I assume we plan to add federation support at some point in the future but I don't believe it's been built in yet, just like subscriptions. We were only preparing for it.


@mengqing in v4 we completely rewrote the entire graphql plugin from the ground up so we didn't get the chance to rebuild all of the v3 features. Time constraints

@Convly
Copy link
Member

Convly commented Apr 12, 2022

@derrickmehaffy It's exactly that. We plan to add it when we'll have enough bandwidth, but we had to make compromises to release the V4 GQL plugin. Both federation & aggregates queries have been cut out of the release but will be implemented sooner or later.

@derrickmehaffy
Copy link
Member

@derrickmehaffy It's exactly that. We plan to add it when we'll have enough bandwidth, but we had to make compromises to release the V4 GQL plugin. Both federation & aggregates queries have been cut out of the release but will be implemented sooner or later.

Cool, that's what I thought. Thanks for the clarification JS 🙏

@mengqing
Copy link
Author

@derrickmehaffy @Convly Thanks for clearing this up for me. For now, I had to use a third-party plugin to transform the schema into a federated specification.

@derrickmehaffy
Copy link
Member

Hey all, we are currently moving many feature requests to our new feedback and feature request website to help clean up the GitHub issues and make it easier for us to review bug reports and fix them.

I have moved this feature to the following URL: https://feedback.strapi.io/developer-experience/p/add-graphql-federation-v4
If you are interested in this feature please feel free to go there and add more comments and/or upvote it there.

For now I will close this and lock it so that all new information goes into our new feedback website.
Thanks!

Developer Experience - Old automation moved this from To be reviewed (Open) to Fixed/Shipped Apr 18, 2022
@derrickmehaffy derrickmehaffy removed this from Fixed/Shipped in Developer Experience - Old Apr 18, 2022
@kentnek
Copy link

kentnek commented May 10, 2022

@derrickmehaffy @Convly Thanks for clearing this up for me. For now, I had to use a third-party plugin to transform the schema into a federated specification.

Hi @mengqing, may I know which plugin you used to add federation and how to integrate it with strapi? Thanks!

@mengqing
Copy link
Author

mengqing commented May 10, 2022

@kentnek I use graphql-transform-federation to transform the strapi schema into a federated spec

@kentnek
Copy link

kentnek commented May 10, 2022

@kentnek I use graphql-transform-federation to transform the strapi schema into a federated spec

Hi @mengqing, I also found that transform plugin but I'm not sure how to add that to my existing Strapi instance. Do you add it as a Strapi extension? Any code example would be greatly appreciated!

@mengqing
Copy link
Author

I basically followed this blog to achieve what I needed

@kentnek
Copy link

kentnek commented May 12, 2022

@mengqing Thank you for the link. I tried to use it in my project but got this error while running:

Cannot find module '@apollo/federation/dist/types'
Error: Cannot find module '@apollo/federation/dist/types'
Require stack:
- ...\node_modules\graphql-transform-federation\dist\transform-federation.js

It looks like the transform plugin needs GraphQL 15 and below:

graphql-transform-federation@2.2.0" has incorrect peer dependency "graphql@^14.0.0 || ^15.0.0".

My project is using GraphQL 16.5.0. May I ask if you encounter the same issue?

@Jeff-Tian
Copy link

@mengqing Thank you for the link. I tried to use it in my project but got this error while running:

Cannot find module '@apollo/federation/dist/types'
Error: Cannot find module '@apollo/federation/dist/types'
Require stack:
- ...\node_modules\graphql-transform-federation\dist\transform-federation.js

It looks like the transform plugin needs GraphQL 15 and below:

graphql-transform-federation@2.2.0" has incorrect peer dependency "graphql@^14.0.0 || ^15.0.0".

My project is using GraphQL 16.5.0. May I ask if you encounter the same issue?

I met the exact same issue. I tried troubleshooting the problem using graphql-transform-federation but to no avail. In the end, I decided to fork it and made some changes before publishing it to @jeff-tian/graphql-transform-federation. This new version resolved the issue for me, and I hope it helps others who encountered the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug issue: discussion A general discussion issue severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve source: plugin:graphql Source is plugin/graphql package status: pending reproduction Waiting for free time to reproduce the issue, or more information
Projects
None yet
Development

No branches or pull requests

5 participants