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

VisitableSchemaType is no longer exported #837

Closed
alvis opened this issue Jun 9, 2018 · 3 comments
Closed

VisitableSchemaType is no longer exported #837

alvis opened this issue Jun 9, 2018 · 3 comments

Comments

@alvis
Copy link
Contributor

alvis commented Jun 9, 2018

Due to 51d2ccf, VisitableSchemaType is no longer exported from index.ts. While it is not a problem for js users, it introduces an issue for typescript users.

The problem is that the constructor function of SchemaDirectiveVisitor takes a VisitableSchemaType as follow
https://github.com/apollographql/graphql-tools/blob/248527d497aa1fe5ff5648e94bf38366121d9d92/src/schemaVisitor.ts#L668-L674

This lead to an extra import { VisitableSchemaType } from 'graphql-tools/dist/schemaVisitor'; for users who use SchemaDirectiveVisitor with typescript.

A simple fix is to re-export VisitableSchemaType. But a better fix is to create an interface for the config variable and export it.

@ghost ghost added the good first issue label Jun 9, 2018
@aliok
Copy link

aliok commented Dec 5, 2018

Because of this problem, we're having trouble when writing tests for our directive.

export class HasRoleDirective extends SchemaDirectiveVisitor {...}

const directive = new HasRoleDirective({
  name: 'testHasRoleDirective',
  args: directiveArgs
})

Ends up:

error TS2674: Constructor of class 'SchemaDirectiveVisitor' is protected and only accessible within the class declaration.

Ok, let's add the constructor:

import { VisitableSchemaType } from 'graphql-tools/dist/schemaVisitor'

export class HasRoleDirective extends SchemaDirectiveVisitor {

  constructor (config: {
    name: string
    args: { [name: string]: any }
    visitedType: VisitableSchemaType
    schema: GraphQLSchema
    context: { [key: string]: any }
  }) {
    super(config)
  }
...
}

Output this time:

error TS2345: Argument of type '{ name: string; args: { [name: string]: any; }; visitedType: import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/packages/apollo-voyager-keycloak/node_modules/graphql-tools/dist/schemaVisitor").VisitableSchemaType; schema: import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/pack...' is not assignable to parameter of type '{ name: string; args: { [name: string]: any; }; visitedType: import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/packages/apollo-voyager-server/node_modules/graphql-tools/dist/schemaVisitor").VisitableSchemaType; schema: import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/node_m...'.
  Types of property 'visitedType' are incompatible.
    Type 'import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/packages/apollo-voyager-keycloak/node_modules/graphql-tools/dist/schemaVisitor").VisitableSchemaType' is not assignable to type 'import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/packages/apollo-voyager-server/node_modules/graphql-tools/dist/schemaVisitor").VisitableSchemaType'.
      Type 'GraphQLSchema' is not assignable to type 'VisitableSchemaType'.
        Type 'import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/packages/apollo-voyager-keycloak/node_modules/@types/graphql/type/schema").GraphQLSchema' is not assignable to type 'import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/node_modules/@types/graphql/type/schema").GraphQLSchema'.
          Types of property 'astNode' are incompatible.
            Type 'import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/packages/apollo-voyager-keycloak/node_modules/@types/graphql/tsutils/Maybe").default<import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/packages/apollo-voyager-keycloak/node_modules/@types/graphql/language/ast").SchemaDefiniti...' is not assignable to type 'import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/node_modules/@types/graphql/tsutils/Maybe").default<import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/node_modules/@types/graphql/language/ast").SchemaDefinitionNode>'.
              Type 'import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/packages/apollo-voyager-keycloak/node_modules/@types/graphql/language/ast").SchemaDefinitionNode' is not assignable to type 'import("/home/aliok/Desktop/code-redhat/aerogear/apollo-voyager-server/node_modules/@types/graphql/language/ast").SchemaDefinitionNode'.
                Types of property 'directives' are incompatible.
                  Type 'ReadonlyArray<DirectiveNode> | undefined' is not assignable to type 'ReadonlyArray<DirectiveNode>'.
                    Type 'undefined' is not assignable to type 'ReadonlyArray<DirectiveNode>'.

Please make the constructor public and also export VisitableSchemaType otherwise it is problematic to create an instance of a directive in typescript.

@richiemccoll
Copy link

@alvis I'm happy to pick this up if you're still looking to get this fixed.

@yaacovCR
Copy link
Collaborator

yaacovCR commented Apr 1, 2020

Closed by #1307, rolled into #1306

@yaacovCR yaacovCR closed this as completed Apr 1, 2020
@yaacovCR yaacovCR mentioned this issue Apr 1, 2020
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants