Giter Club home page Giter Club logo

Comments (7)

SolarLiner avatar SolarLiner commented on May 18, 2024 2

Hi, for posterity, I have found an alternative method with graphql-transform-federation which allows adding federation-related directives to the schema that the Neo4jGraphQL generator does not know about.
Simply generate the schema as you would, and transform the schema as you're passing it to the ApolloServer configuration, like this:

  // Create ApolloServer instance that will serve GraphQL schema created above
  // Inject Neo4j driver instance into the context object, which will be passed
  //  into each (autogenerated) resolver
  const neoServer = new ApolloServer({
    context: ({ req }) => ({ req, driver }),
    schema: transformSchemaFederation(neoSchema.schema, {
      Query: { extend: true },
      User: {
        extend: true, keyFields: ["userId"], fields: {
          userId: { external: true },
        }
      }
    }),
    introspection: true,
  });

This seems to work quite well. Thanks anyways for the initial idea,as it made me stumble into this alternative workaround.

from graphql.

darrellwarde avatar darrellwarde commented on May 18, 2024

Hey @SolarLiner, while it sounds like we maybe need to expose our resolvers, [@graphql-tools/utils](https://www.npmjs.com/package/@graphql-tools/utils) exposes a function getResolversFromSchema` which you may be able to use to get our resolvers. Give it a go and let me know if it works?

from graphql.

darrellwarde avatar darrellwarde commented on May 18, 2024

Rough example of something which might work:

const { getResolversFromSchema } = require("@graphql-tools/utils");
const { mergeTypeDefs } = require("@graphql-tools/merge");
const { makeExecutableSchema } = require("@graphql-tools/schema");
const { Neo4jGraphQL } = require("@neo4j/graphql");
const { printSchema } = require("graphql");

const neoSchema = new Neo4jGraphQL({
  typeDefs,
  driver,
});

const someService = new ApolloServer({
  schema: buildFederatedSchema([
    {
      typeDefs: printSchema(neoSchema.schema),
      resolvers: getResolversFromSchema(neoSchema.schema),
    },
  ]),
  context: ({ req }) => {
    return {
      driver,
      req,
    };
  },
});

from graphql.

darrellwarde avatar darrellwarde commented on May 18, 2024

(You may need to wrap printSchema(neoSchema.schema) with gql() for it work)

from graphql.

SolarLiner avatar SolarLiner commented on May 18, 2024

Being fairly new with GraphQL I had not even thought of looking into graphql-tools. This seems to be promising, thank you!

from graphql.

process0 avatar process0 commented on May 18, 2024

Note, this only works if you do not extend any typedefs.

from graphql.

matola avatar matola commented on May 18, 2024

Has there been any movement on this (support for neo4j graphQL endpoints as a subgraph)? I see a couple of pretty stale projects that attempt to help? The example above doesn't work as you would need to include the federation schema fragment in the neo4j schema, but then the buildSubgraph complains that they are already defined.

from graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.