add directives definitions to import?
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
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
on which file did you wrote this code? Thanks
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)
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.
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.