-
-
Notifications
You must be signed in to change notification settings - Fork 822
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
introspectSchema throw when underlying schema have contraint directives #842
Comments
Same problem here with a similar setup, but error is a bit different:
|
@rainum your issue is unrelated IMO. You need to add this to your SDL: directive @constraint(
# String constraints
minLength: Int
maxLength: Int
startsWith: String
endsWith: String
notContains: String
pattern: String
format: String
# Number constraints
min: Int
max: Int
exclusiveMin: Int
exclusiveMax: Int
multipleOf: Int
) on INPUT_FIELD_DEFINITION As soon as you add it you'll get the error from above. |
@koresar yes, you're right. Now I'm getting the |
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:
Now I'm using Apollo Stack v2 (currently RC). It has solved all the problems I had. |
There is more context to the above comment that can be found below (doesn't work): There is a hacky workaround suggested there that may not work for everyone. Any solution or update on this? |
Same problem. When I tried to define new type in directive for field I get the same error. My definition:
Error on introspection:
|
Is there still no solution for this? Input field directives still break introspection in playground. |
Some issues are related to #1022, i.e. requirement to declare directives in schema with graphql-js v14. Planned workaround there is to have directive package authors also include instructions/exports for the directive sdl or to add option to assume valid sdl when calling buildSchema, although both less than ideal, definitely open to suggestions re all of above. Other issues relate to constraint directive package itself which creates multiple different scalars of identical name, to attempt to avoid leaking these new constraint types via introspection, which is not officially supported, as far as I know, and makes the entire directive stop working in v5. For a different approach, see other packages available in #789. Closing this issue for now, please feel free to reopen if more specific action needed. |
@yaacovCR Why is this not officially supported when it's the recommended implementation on the docs which is also afflicted by this issue? https://www.apollographql.com/docs/apollo-server/schema/creating-directives/#enforcing-value-restrictions |
That example is still supported, notice the unique name of the created type, I believe that is the difference between supported example and your constraint directive. I may be missing something, addressing this several months to years later. Ideally, I would like to continue to support the workflow you initiated, but I can't say that I see how at present. |
Could you elaborate on unique? The example shows the name is based on the |
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. |
The reason why the constraint directive implementation no longer works in V5 is because schema healing has been reworked to no longer depend on -- or require -- mutation of the original schema. This is part of an attempt throughout the code base to create immutable versions of all schema and type modification functions, as useful functions can then potentially be submitted to upstream graphql-js. |
We use the same approach as in the Apollo docs (https://www.apollographql.com/docs/graphql-tools/schema-directives/#enforcing-value-restrictions) to enforce a restriction on fields that have been annotated with a custom directive. Even with unique names for each instance of the custom scalar type we're seeing the I noticed that the error disappears if we declare the name(s) of the custom scalars with We'd like to enforce restrictions on input type fields based on directive annotations in the SDL so there doesn't seem to be a different solution than using custom scalar types either? |
@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. |
@confuser et al, see #1468, I think for v6, we can restore the original v4 behavior without major issues so the directive will once again work. I don't think that will help with the underlying schema introspection issue, but at least we don't have to make the problem worse. This is because the v5 schema healing that was causing a problem is really no longer in use within the code base as we have moved throughout to no longer modify schemas in place, but to rather create new schemas. See #1463 for a directive-driven functional approach to schema modification that uses mapSchema to no longer modify the schema in place. |
Thanks @yaacovCR I've released v2 of graphql-constraint-directive which appears to be working well with v6 |
Cool! Just took a look, looks like you found a satisfactory approach for unique type names. Your code made me think of something -- it looks like you are not letting your directive users customize the directive name. (https://github.com/confuser/graphql-constraint-directive/blob/master/index.js#L51) Did you think we didn't highlight well enough how to do that, or did you just choose not to? I think we did forget to give an example of how you could export a directive definition that is also customizable with a type name. It would be fairly straightforward to export it as a function that embeds the desired directive name within the string. This is all to pre-emptively avoid namespace clashes between different directives. I think the constraint directive seems to be one of the more popular directives, and I suppose unlikely to cause problems by staking out a claim to that name first. You could always add the ability to customize the name later... |
@yaacovCR I chose not to at this time to avoid fragmentation. The examples are clear apart from The authDirective example shows an export of the type defs and a function to pass in the custom namespace, but it's not clear how that namespace is passed to the
|
…r directives (including the directive definition itself) based on suggestion by @confuser #842 (comment)
Thanks, I gave it a try... |
/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
:My underlying schema looks like that:
Edit: Related to confuser/graphql-constraint-directive#2
The text was updated successfully, but these errors were encountered: