neo4j / graphql

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations.
https://neo4j.com/docs/graphql-manual/current/
Apache License 2.0
508 stars 149 forks source link

Typescript raises a typing error when using Neo4GraphQL with ApolloServer v4 #3038

Closed cptflammin closed 1 year ago

cptflammin commented 1 year ago

When using Neo4GraphQl with Apolloserver v4, a Typescript error is raised. Side note, https://neo4j.com/docs/graphql-manual/current/getting-started/ should be updated to latest version of Apollo v4, as v2 and v3 are now deprecated (EOL Oct 2023) By the way, we miss examples to properly setup a graphql server with NeoGraphQL API in both serverless and non-serverless environments, that would be helpful

TS2345: Argument of type '{ neoSchema: Neo4jGraphQL; }' is not assignable to parameter of type 'ApolloServerOptions<BaseContext>'.   Object literal may only specify known properties, but 'neoSchema' does not exist in type 'ApolloServerOptions<BaseContext>'. Did you mean to write 'schema'

Code:

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

export const graphqlHandler = startServerAndCreateLambdaHandler(
    new ApolloServer({
        neoSchema,    <==== Error raised here
    }),
    // We will be using the Proxy V2 handler
    handlers.createAPIGatewayProxyEventV2RequestHandler(),
);

Packages versions: graphapi@1.0.0 /Users/wtf/Development/myApp/graphAPI ├── @apollo/server@4.5.0 ├── @as-integrations/aws-lambda@2.0.1 ├── @neo4j/graphql-ogm@3.17.1 ├── @neo4j/graphql@3.17.1 ├── graphql@16.6.0 ├── neo4j-driver@5.6.0 └── typescript@4.9.5

neo4j-team-graphql commented 1 year ago

Many thanks for raising this bug report @cptflammin. :bug: We will now attempt to reproduce the bug based on the steps you have provided.

Please ensure that you've provided the necessary information for a minimal reproduction, including but not limited to:

If you have a support agreement with Neo4j, please link this GitHub issue to a new or existing Zendesk ticket.

Thanks again! :pray:

neo4j-team-graphql commented 1 year ago

Many thanks for raising this bug report @cptflammin. :bug: We will now attempt to reproduce the bug based on the steps you have provided.

Please ensure that you've provided the necessary information for a minimal reproduction, including but not limited to:

If you have a support agreement with Neo4j, please link this GitHub issue to a new or existing Zendesk ticket.

Thanks again! :pray:

cptflammin commented 1 year ago

@johnymontana Following the Neo4j YT channel, you may be the right the person to provide informed feedback :)

mjfwebb commented 1 year ago

Hi @cptflammin, here's an example of @neo4j/graphql being used with Apollo Server v4 and Next.js so it should be helpful as to how to create serverless functions: https://github.com/vercel/next.js/tree/canary/examples/with-apollo-neo4j-graphql

In general though, if you follow the V4 getting started docs, it isn't too dissimilar to V3.

A small example using V4 with our library:

...

import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";

...

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

const schema = await neoSchema.getSchema();

const server = new ApolloServer({ schema });
const { url } = await startStandaloneServer(server, {
    listen: { port: 4000 },
});

console.log(`Online at ${url}`);
darrellwarde commented 1 year ago

As @mjfwebb has pointed out, you need to call getSchema() on the library to get the actual schema! Closing this one, you can ask for this kind of help in our #graphql channel in Discord.