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
507 stars 149 forks source link

Error: Unknown directive "@auth" #3030

Closed harryjin closed 1 year ago

harryjin commented 1 year ago

Describe the bug During migrating from neo4j-graphql-js to @neo4j/graphql, it don't recognize @auth directive.

Type definitions Type definitions

To Reproduce

  1. Make Schema with @auth directive
type URL @auth(rules: [{ isAuthenticated: true }]) {
  _id: ID!
  address: String!
  status_code: Int
  canonical: String
  title_1: String
  titleLen: Int
  h1_1: String
  h1_1Len: Int
  fullText: String
  fullHTMLText: String
  links: [URL!]! @relationship(type: "LINKS_TO", direction: OUT)
  outlinks: Int
  inlinks: Int
}
  1. Build the project and Run.
  2. When get schema, this error occur. const schema = await neoSchema.getSchema()

Screenshots image

System (please complete the following information):

Additional context Add any other context about the problem here.

neo4j-team-graphql commented 1 year ago

Many thanks for raising this bug report @harryjin. :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 @harryjin. :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:

MacondoExpress commented 1 year ago

I tried to reproduce your issue with the latest version of the library 3.17.1, with the reproduction step that you have provided without any success. Could you share more details on how to reproduce it? I can share the reproduction step I've used:

async function run() {
    const driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("user", "password"));
    const typeDefs = gql`
        type URL @auth(rules: [{ isAuthenticated: true }]) {
            _id: ID!
            address: String!
            status_code: Int
            canonical: String
            title_1: String
            titleLen: Int
            h1_1: String
            h1_1Len: Int
            fullText: String
            fullHTMLText: String
            links: [URL!]! @relationship(type: "LINKS_TO", direction: OUT)
            outlinks: Int
            inlinks: Int
        }
    `;
    const neoSchema = new Neo4jGraphQL({
        typeDefs,
        driver,
        plugins: {
            auth: new Neo4jGraphQLAuthJWTPlugin({
                secret: "secret",
                noVerify: false,
            }),
        },
    });

    const schema = await neoSchema.getSchema();
}
run()
harryjin commented 1 year ago

I tried to reproduce your issue with the latest version of the library 3.17.1, with the reproduction step that you have provided without any success. Could you share more details on how to reproduce it? I can share the reproduction step I've used:

async function run() {
    const driver = neo4j.driver("bolt://localhost:7687", neo4j.auth.basic("user", "password"));
    const typeDefs = gql`
        type URL @auth(rules: [{ isAuthenticated: true }]) {
            _id: ID!
            address: String!
            status_code: Int
            canonical: String
            title_1: String
            titleLen: Int
            h1_1: String
            h1_1Len: Int
            fullText: String
            fullHTMLText: String
            links: [URL!]! @relationship(type: "LINKS_TO", direction: OUT)
            outlinks: Int
            inlinks: Int
        }
    `;
    const neoSchema = new Neo4jGraphQL({
        typeDefs,
        driver,
        plugins: {
            auth: new Neo4jGraphQLAuthJWTPlugin({
                secret: "secret",
                noVerify: false,
            }),
        },
    });

    const schema = await neoSchema.getSchema();
}
run()

Thanks for your help. Please use follow schema. https://drive.google.com/file/d/1uxj6l1cXxCZhEWzIbWx_Ty2rHZQ28CjX/view?usp=share_link

darrellwarde commented 1 year ago

I haven't even reproduced, but given there are 3 errors, I'm 99% sure the problem fields are:

You cannot use our @auth directive on a field resolved by a custom resolver. The @auth directive is assessed in Cypher, and with a custom resolver there is no Cypher.

darrellwarde commented 1 year ago

Closing this one due to inactivity, and this is not a known problem. I suggest using something like GraphQL Shield if you want authentication on fields resolved by custom resolvers.