Skip to content

Directives missing in SDL #986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
carnun opened this issue Aug 12, 2021 · 1 comment
Closed

Directives missing in SDL #986

carnun opened this issue Aug 12, 2021 · 1 comment
Labels
Invalid 👎 This doesn't seem right

Comments

@carnun
Copy link

carnun commented Aug 12, 2021

Describe the Bug
When I generate the SDL from a set of resolvers which use the @ Directive decorator the directives do not appear in the SDL. I see similar behaviour when running a live graphql server.

I'm not sure whether this is a bug, or whether this is the intended behavior since I couldn't deduce from https://typegraphql.com/docs/directives.html whether directives are supported in the SDL generated by type-graphql, in which case #965 may help clarify. Otherwise it could related to the original issue reported as graphql/graphql-js#1343.

PS: the reason I'm looking for this functionality is so that I can eventually integrate more seamlessly with Apigee which uses a @scope directive to generated the authentication config - https://github.com/apigee/graphql-authz.

To Reproduce
Compile and run the following code

// test.ts
import 'reflect-metadata'
import { buildSchemaSync, ObjectType, Field, Resolver, Query, Directive } from 'type-graphql'
import path from 'path'

@ObjectType()
class Config {
  @Field()
  VERSION: string
}

@Resolver(() => Config)
class ConfigResolver {
  @Directive('@auth(requires: USER)')
  @Query(() => Config)
  getConfig(): Config {
    return {
      VERSION: '1.0.0',
    }
  }
}

const fullSchemaPath = path.resolve(__dirname, './test.graphql')
buildSchemaSync({
  resolvers: [ConfigResolver],
  emitSchemaFile: fullSchemaPath,
})
console.log(`Generated full schema - ${fullSchemaPath}`)

The text.graphql file has the following contents

# -----------------------------------------------
# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!!
# !!!   DO NOT MODIFY THIS FILE BY YOURSELF   !!!
# -----------------------------------------------

type Config {
  VERSION: String!
}

type Query {
  getConfig: Config!
}

Expected Behavior
I would expect the file contents to contain the directive, e.g.

type Query @auth(requires: USER) {
  getConfig: Config!
}

Logs
N/A

Environment:

  • OS: MacOS 11.4
  • Node v12.22.1
  • Package version 1.1.1
  • TypeScript version 4.3.5
@MichalLytek
Copy link
Owner

Please read the docs more carefully:

image

@MichalLytek MichalLytek added the Invalid 👎 This doesn't seem right label Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid 👎 This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants