Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

auth directives missing from augmented schema #24

Closed
AdrienLemaire opened this issue May 25, 2020 · 2 comments
Closed

auth directives missing from augmented schema #24

AdrienLemaire opened this issue May 25, 2020 · 2 comments

Comments

@AdrienLemaire
Copy link

server:

import { IsAuthenticatedDirective } from "graphql-auth-directives";
import { makeAugmentedSchema } from "neo4j-graphql-js";
import neo4j from "neo4j-driver";
import { typeDefs } from "./graphql-schema";

const schema = makeAugmentedSchema({
  typeDefs,
  schemaDirectives: {
    isAuthenticated: IsAuthenticatedDirective,
    //hasRole: HasRoleDirective,
    //hasScope: HasScopeDirective,
  },
});

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

in my client, apollo.config.js

module.exports = {
  client: {
    service: {
      name: "project",
      // This option uses the resulting schema from makeAugmentedSchema
      url: "http://localhost:4001/graphql",
      skipSSLValidation: true,
    },
}

When I run from my client npx apollo client:download-schema schema.graphql, I cannot find the isAuthenticated directive. Everything else, like neo4j directives, is shown properly.

directive @cypher(statement: String) on FIELD_DEFINITION

directive @relation(name: String, direction: _RelationDirections, from: String, to: String) on FIELD_DEFINITION | OBJECT

directive @additionalLabels(labels: [String]) on OBJECT

directive @MutationMeta(relationship: String, from: String, to: String) on FIELD_DEFINITION

directive @neo4j_ignore on FIELD_DEFINITION

...

It looks like a bug with graphql-auth-directives, but since no other user reported it, I suppose it's my setup that's incorrect, though I cannot figure this out on my own. Any idea?

@AdrienLemaire
Copy link
Author

When querying directives with introspection from the chrome apollo plugin

{
  __schema{
    directives {
      name
      description
    }
  }
}

I'm getting

{
  "data": {
    "__schema": {
      "__typename": "__Schema",
      "directives": [
        {
          "__typename": "__Directive",
          "name": "cypher",
          "description": ""
        },
        {
          "__typename": "__Directive",
          "name": "relation",
          "description": ""
        },
        {
          "__typename": "__Directive",
          "name": "additionalLabels",
          "description": ""
        },
        {
          "__typename": "__Directive",
          "name": "MutationMeta",
          "description": ""
        },
        {
          "__typename": "__Directive",
          "name": "neo4j_ignore",
          "description": ""
        },
        {
          "__typename": "__Directive",
          "name": "skip",
          "description": "Directs the executor to skip this field or fragment when the `if` argument is true."
        },
        {
          "__typename": "__Directive",
          "name": "include",
          "description": "Directs the executor to include this field or fragment only when the `if` argument is true."
        },
        {
          "__typename": "__Directive",
          "name": "deprecated",
          "description": "Marks an element of a GraphQL schema as no longer supported."
        }
      ]
    }
  },
  "loading": false,
  "networkStatus": 7,
  "stale": false
}

It appears my isAuthenticated schema directive isn't read by makeAugmentedSchema

@AdrienLemaire
Copy link
Author

Oversight, missed the documentation in https://grandstack.io/docs/neo4j-graphql-js-middleware-authorization

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant