Skip to content

Graphql with Apollo Federation gives an Error on Entities: Non-shareable field is resolved from multiple subgraphs #6160

Open
@kunaliiti

Description

@kunaliiti

Describe the bug
I created two very simple subgraphs both using neo4j/graphql pointing to different neo4j instances. Both the subgraphs had just one entity "User" with different fields respectively. When combining these two subgraphs with Apollo Rover CLI. It gives out errors:

UNKNOWN: Non-shareable field "Query.users" is resolved from multiple subgraphs: it is resolved from subgraphs "gr1" and "gr2" and defined as non-shareable in all of them

Type definitions
Subgraph gr1 (app1.js):

import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { Neo4jGraphQL } from "@neo4j/graphql";
import neo4j from "neo4j-driver";

const typeDefs = `#graphql
extend schema @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key", "@shareable", "@external", "@override"])

type User @key(fields: "id") {
  id: ID!
  name: String!
}
`;

const driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "neo4j"));

const neo4jGraphQL = new Neo4jGraphQL({
    typeDefs,
    driver,
})

const schema = await neo4jGraphQL.getSubgraphSchema();

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

const { url } = await startStandaloneServer(server, {
    context: async ({ req }) => ({ req, sessionConfig: { database: "fed1" } }),
    listen: { port: 5001 },
});
console.log(`🚀  Server ready at ${url}`);

Subgraph gr2 (app2.js):

import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { Neo4jGraphQL } from "@neo4j/graphql";
import neo4j from "neo4j-driver";

const typeDefs = `#graphql
extend schema @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key", "@shareable", "@external", "@provides"])

type User @key(fields: "id") {
  id: ID!
  age: Int!
}
`;

const driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("neo4j", "neo4j"));

const neo4jGraphQL = new Neo4jGraphQL({
  typeDefs,
  driver,
})

const schema = await neo4jGraphQL.getSubgraphSchema();

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

const { url } = await startStandaloneServer(server, {
  context: async ({ req }) => ({ req, sessionConfig: { database: "fed2" } }),
  listen: { port: 5002 },
});
console.log(`🚀  Server ready at ${url}`);

Apollo Rover Configuration:

federation_version: =2.3.2
subgraphs:

  # Subgraph introspection
  gr1:
    routing_url: http://localhost:5001  # <- can be omitted if the same as introspection URL
    schema:
      subgraph_url: http://localhost:5001

  # Subgraph introspection
  gr2:
    routing_url: http://localhost:5002  # <- can be omitted if the same as introspection URL
    schema:
      subgraph_url: http://localhost:5002

To Reproduce
Steps to reproduce the behavior:

  1. node app1.js
  2. node app2.js
  3. npx rover supergraph compose --config ./supergraph.yaml --output supergraph.graphql
  4. See error
Image

Expected behavior
Since the node "User" is defined as entity using the @key directive the below error should not be shown:

UNKNOWN: Non-shareable field "Query.users" is resolved from multiple subgraphs: it is resolved from subgraphs "gr1" and "gr2" and defined as non-shareable in all of them

System (please complete the following information):

  • OS: macOS
  • Version
    @apollo/server: 4.11.3,
    @neo4j/graphql: 5.12.0,
    graphql: 16.10.0,
    neo4j-driver: 5.28.1
    Rover: 0.28.1
  • Node.js version: v20.15.1

Additional context
I also tried this with @neo4j/graphql: 6.6.0 and got the same error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingconfirmedConfirmed bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions