graphql-tools: introspectSchema throw when underlying schema have contraint directives
/label bug
I’m trying to make schema stitching with underlying schemas having GraphQL contraint directives.
But the stitching process is throwing an error on introspectSchema
:
Error: Invalid or incomplete schema, unknown type: ConstraintString.
Ensure that a full introspection query is used in order to build a client schema.
at getNamedType (/Users/yves/repo/node_modules/graphql/utilities/buildClientSchema.js:96:13)
at getType (/Users/yves/repo/node_modules/graphql/utilities/buildClientSchema.js:87:12)
at getInputType (/Users/yves/repo/node_modules/graphql/utilities/buildClientSchema.js:104:16)
at buildInputValue (/Users/yves/repo/node_modules/graphql/utilities/buildClientSchema.js:249:16)
at /Users/yves/repo/node_modules/graphql/jsutils/keyValMap.js:28:31
at Array.reduce (<anonymous>)
at keyValMap (/Users/yves/repo/node_modules/graphql/jsutils/keyValMap.js:27:15)
at buildInputValueDefMap (/Users/yves/repo/node_modules/graphql/utilities/buildClientSchema.js:243:36)
at fields (/Users/yves/repo/node_modules/graphql/utilities/buildClientSchema.js:218:16)
at resolveThunk (/Users/yves/repo/node_modules/graphql/type/definition.js:370:40)
My underlying schema looks like that:
input AddItemInput {
name: String! @constraint(minLength: 2, maxLength: 40)
}
import ConstraintDirective from "graphql-constraint-directive";
export default makeExecutableSchema({
typeDefs,
resolvers,
schemaDirectives : { constraint: ConstraintDirective }
});
Edit: Related to https://github.com/confuser/graphql-constraint-directive/issues/2
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 22
Commits related to this issue
- fix: Unknown ConstraintType issue on graphigl @see: https://github.com/apollographql/graphql-tools/issues/842 — committed to joonilkim/vevey by joonilkim 5 years ago
- update docs to better illustrate how to export type defs necessary for directives (including the directive definition itself) based on suggestion by @confuser https://github.com/ardatan/graphql-tool... — committed to ardatan/graphql-tools by yaacovCR 4 years ago
Same problem. When I tried to define new type in directive for field I get the same error.
My definition:
Error on introspection:
@rainum your issue is unrelated IMO. You need to add this to your SDL:
As soon as you add it you’ll get the error from above.
Thanks @yaacovCR I’ve released v2 of graphql-constraint-directive which appears to be working well with v6
@mfellner , see below
Hopefully that will work then, as we currently include tests that – in theory – should guarantee support.
The tests above assume the directive names are declared. This is annoying, see #1022, and comment above for thoughts about potentials for workarounds.
It should work. If you believe you are following the pattern in the documented example and associated linked test above, you should open a new issue as bug report with a minimal reproduction. I would suggest starting from the code within the test, and the creation of a failing test that mimics your code.
There is another alternative – checking inputs on field resolution. See end of discussion at #789. Highlights are two relatively recent userland packages, which seems to me to be significant progress and required a great deal of thought and work by their authors:
See, as well, suggestions for changes within the graphql spec referenced by @alexstrat at the end of the README for his project.
I meant unique in the sense that the length constraint is enforced by using a specific type with the appropriate length.
My understand of the issues in #789 relate to the desire to use validation by wrapping arguments rather than by using the serialized and parts functions within a dedicated scalar type. This requires using the directive to simply mark the schema with metadata and an additional function to wrap the required arguments all over the schema according to the metadata.
See #1234 to track potentially new approach to directives, ie functions that take a set of directive names as arguments and return a function that takes a schema that uses those directives in some way as an argument and returns a transformed schema.
There is more context to the above comment that can be found below (doesn’t work): https://github.com/confuser/graphql-constraint-directive/issues/2
There is a hacky workaround suggested there that may not work for everyone.
Any solution or update on this?
I have solved the problem, people.
The high level solution: do not use Prisma and Apollo packages in the same project. They are often incompatible.
What I did:
graphql-yoga
andgraphql-import
packages).#import
statements and used Apollo’smergeSchema()
JS function).Now I’m using Apollo Stack v2 (currently RC). It has solved all the problems I had.
I debugged a little. TL;DR: The
makeExecutableSchema
does not replace the directive object in schema.graphql-import
people tell you to “declare the@constraint
scalar in .graphql file”. It effectively creates a directive object in schema. Which is right thing to do IMO. My IDE stops complaining about “undeclared directive!”.makeExecutableSchema
accepts theschemaDirectives
and applies the schema visitor to them. But it does not replace the previously declared directive generated bygraphql-import
.Here is a screenshot. I made it in node.js debugger one step before exiting the
makeExecutableSchema
. Basically, thatschema
variable is what I get.As the result, the
@constraint
directive is not being visited at runtime.Everything above can be wrong due to my limited understanding.
Same problem here with a similar setup, but error is a bit different: