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

add directives definitions to import? #201

Open
terion-name opened this issue Jul 11, 2018 · 5 comments
Open

add directives definitions to import? #201

terion-name opened this issue Jul 11, 2018 · 5 comments

Comments

@terion-name
Copy link

terion-name commented Jul 11, 2018

I have an app that parses schemas and is processing them.

I want to use a directive in these schemas, but not to write there it's definition (alike Prisma directives in datamodel). But I can't run import these schemas:

Error: Directive relation: Couldn't find type relation in any of the schemas.
    at collectDirective (.../node_modules/graphql-import/src/definition.ts:172:15)
    at Array.forEach (<anonymous>)
    at collectNode (.../node_modules/graphql-import/src/definition.ts:161:21)
    at .../node_modules/graphql-import/src/definition.ts:135:7
    at Array.forEach (<anonymous>)

graphql-import only works if I supply path to schema, not the schema content, so I can't simply concat directive definition during import.

So is there a way to overcome this? To add definitions during import? Or make it simply to ignore absence of relation

@terion-name
Copy link
Author

Currently what I've done: I've copied scripts to project and changed main func like this:

export function importSchema(
    schema: string,
    schemas?: { [key: string]: string },
    ...typeDefs: string[] // added this
): string {
  const sdl = [read(schema, schemas) || schema, ...typeDefs].join(' '); // changed this

And it works like a charm (const importedSchema = importSchema(schema, null, relationDerictiveDefinition);). Don't know either something like this should be added to library

@armij
Copy link

armij commented Aug 22, 2018

on which file did you wrote this code? Thanks

@ecker00
Copy link

ecker00 commented Jan 31, 2019

Unless I'm missing something, I'm also struggling with the same. importSchema() does not support adding in schemaDirectives {}, and will throw errors at all the @Directives it comes across. (While makeExecutableSchema() does support it) (Update: That was incorrect)

@ecker00
Copy link

ecker00 commented Jan 31, 2019

This seem to be related #153 as it's any directive that's not directly declared in the imported schema, but imported at a later stage. In my case I would like to use constraint from graphql-constraint-directive.

Seems @terion-name suggestion could resolve this, by adding it as an argument into the importSchema() function. Would this feature conflict with other parts of graphql-import?

Update: Works fine as long as the directive has a basic defenition in the schema, which seems logical:

directive @constraint(
  minLength: Int,
  maxLength: Int,
   …
} on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION

Sorry for any confusion.

@ardatan ardatan added the bug label Jan 1, 2020
@ardatan
Copy link
Owner

ardatan commented Jan 1, 2020

Hi @atten !
In 1.0.0 beta release, we introduced a lot of changes.
Could you install graphql-import@beta to try new changes? Don't forget to modify your code regarding to the migration notes in README.
https://github.com/ardatan/graphql-import#updating-from-07x

Let us know if your issue still persists.

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