Error when trying to add a directive with any arguments via makeExtendSchemaPlugin
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 625
- Avg merge
- 5h 23m
- Merged PRs (30d)
- 24
Description
### Summary
I'm trying to write a Postgraphile plugin which (among other things) adds several directives to my GraphQL schema. Adding directives via `makeExtendSchemaPlugin` seems to work if those directives have no arguments, but if they do have arguments, I see an error:
Plugin code
```js
const AddDirectivePlugin = makeExtendSchemaPlugin(() => {
return {
typeDefs: gql`
directive @foobar(x: Int!) on FIELD_DEFINITION
`,
};
});
```
Error messsage:
```
/Users/ben/src/ouch-my-finger/node_modules/graphile-build/dist/makeNewBuild.js:232
throw new Error("Must not call build.getTypeByName before 'init' phase is complete");
^
Error: Must not call build.getTypeByName before 'init' phase is complete
at Object.getTypeByName (/Users/ben/src/ouch-my-finger/node_modules/graphile-build/dist/makeNewBuild.js:232:23)
at getType (/Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:436:32)
at getType (/Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:443:53)
at /Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:527:34
at Array.reduce ()
at getArguments (/Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:524:25)
at /Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:312:42
at Array.forEach ()
at init (/Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:126:30)
at SchemaBuilder.applyHooks (/Users/ben/src/ouch-my-finger/node_modules/graphile-build/dist/SchemaBuilder.js:98:30)
```
### Steps to reproduce
1. Check out the `add-directive-with-args-error` branch of my fork of `ouch-my-finger` [here](https://github.com/benweint/ouch-my-finger/tree/add-directive-with-args-error)
2. Within the working copy, try to start a postgraphile server (`yarn postgraphile -c postgres:///my_db -s app_public`) - it shouldn't matter what's in the DB
### Expected results
I would expect the directive to be added to the GraphQL schema presented by Postgraphile, and to see no error on startup.
### Actual results
I get this error:
```
❯ yarn postgraphile -c postgres:///ben -s ben
yarn run v1.22.21
warning ../../package.json: No license field
$ postgraphile -c postgres:///ben -s ben
Server listening on port 5678 at http://[::]:5678/graphql
/Users/ben/src/ouch-my-finger/node_modules/graphile-build/dist/makeNewBuild.js:232
throw new Error("Must not call build.getTypeByName before 'init' phase is complete");
^
Error: Must not call build.getTypeByName before 'init' phase is complete
at Object.getTypeByName (/Users/ben/src/ouch-my-finger/node_modules/graphile-build/dist/makeNewBuild.js:232:23)
at getType (/Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:436:32)
at getType (/Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:443:53)
at /Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:527:34
at Array.reduce ()
at getArguments (/Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:524:25)
at /Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:312:42
at Array.forEach ()
at init (/Users/ben/src/ouch-my-finger/node_modules/graphile-utils/dist/makeExtendSchemaPlugin.js:126:30)
at SchemaBuilder.applyHooks (/Users/ben/src/ouch-my-finger/node_modules/graphile-build/dist/SchemaBuilder.js:98:30)
```
Contributor guide
Assessment
This issue has not been assessed yet.