Skip to content
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

A custom directive didn't apear in scheme #1278

Closed
jangot opened this issue Dec 8, 2020 · 4 comments
Closed

A custom directive didn't apear in scheme #1278

jangot opened this issue Dec 8, 2020 · 4 comments

Comments

@jangot
Copy link

jangot commented Dec 8, 2020

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Hello.
I have no a lot of experience in graphQL.
I try to add a custom directive to my project. I just copy-pasted the code from the documentation.
So I created UpperCaseDirective and if I apply it to my model as a decorator it works but I want to apply it on my client-side and it doesn't work. Additionally, I created DeprecatedDirective and after applying the directive for a model's field it started to be deprecated but just in playground. My generated scheme has no mentions about deprecated fields. It is not a problem if I use a single graphql service but for graphQL federation, the fields lose deprecated.

Current behavior

I added 2 directives

// app.t
schemaDirectives: {
    upper: UpperCaseDirective,
    deprecated: DeprecatedDirective,
},

// user-model.ts
export class User {
    @Directive('@deprecated')
    @Field({ description: 'Hashed user id' })
    key: string;

    @Directive('@upper')
    @Field()
    firstName: string;
}

Expected behavior

I expected the directive should appear on the top of graphQL schema. At list deprecated should be after the field.

I confused. I spent many hours to understand what happens and have no result.

Please answer Is an opportunity to add directives to my scheme?

@mrkswrnr
Copy link

Looks like this is a duplicate of #1239 which was closed due to missing information.
Here is some additional information :-)

Minimal reproduction of the problem with instructions

git clone https:/mrkswrnr/nestjs-graphql-missing-directive.git
cd nestjs-graphql-missing-directive
npm i
npm run start

open http://localhost:3000/graphql

Here is the schema you should see

directive @specifiedBy(url: String!) on SCALAR
type Query {
  tests: [Test!]!
}

type Test {
  id: ID!
  name: String!
}

The upper directive is not defined and missing above the "name" field. Also there is no deprecation directive above the tests query.

Running npm run test or npm run test:e2e also indicates the directive "upper" is missing.

Environment

Nest version: 7.6.1
Nest graphql version: 7.9.1
Apollo Server version: 2.19.0

@kamilmysliwiec
Copy link
Member

Additionally, I created DeprecatedDirective and after applying the directive for a model's field it started to be deprecated but just in playground. My generated scheme has no mentions about deprecated fields.

This is the expected behavior.

This issue has been discussed several times in the past. Your directives will be applied to types, but they won't be visible in the generated GraphQL schema file. You can find more details about - why - this is the case here graphql/graphql-js#1343

@LeoVS09
Copy link

LeoVS09 commented Dec 14, 2020

Hi, I not understand why this issue is closed?Discussion which you mentioned is still open. And in any way, deprecated directive must appears in schema, as in other case it breaks Apollo Federation behaviour.
I interested in custom directives too, and think many another developers.

@kamilmysliwiec
Copy link
Member

Because there's no sense to track this in multiple places. Once this is supported by GraphQL, we'll surely implement this in this package.

@nestjs nestjs locked as off-topic and limited conversation to collaborators Dec 14, 2020
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

4 participants