Comments (3)
Amazing thanks @cabelitos will try it out and report back.
from apollo-validation-directives.
Can confirm this is working as expected. Thanks for the help 🥇
from apollo-validation-directives.
Hello @hobochild,
After some investigation we concluded that you can use the SchemaDirectiveVisitor
from graphql-tools/utils
to revisit the whole schema after it was mocked. Doing this, it will repopulate the needed resolvers and everything will work as expected.
I'm attaching a diff in this comment, which "fixes" the example that you provided to us.
Please, let me know if you need help.
diff --git a/package.json b/package.json
index 8376271..eb29d7d 100644
--- a/package.json
+++ b/package.json
@@ -5,6 +5,7 @@
"main": "schema.js",
"dependencies": {
"@graphql-tools/mock": "^6.2.4",
+ "@graphql-tools/utils": "^6.2.4",
"@profusion/apollo-validation-directives": "^2.0.3",
"apollo-server-express": "^2.18.2"
},
diff --git a/schema.js b/schema.js
index 1c79ac5..5de09c0 100644
--- a/schema.js
+++ b/schema.js
@@ -18,6 +18,10 @@ const resolvers = {
}
};
+export const schemaDirectives = {
+ pattern,
+}
+
const schema = makeExecutableSchema({
typeDefs: [
typeDefs,
@@ -25,9 +29,7 @@ const schema = makeExecutableSchema({
...pattern.getTypeDefs()
],
resolvers,
- schemaDirectives: {
- pattern: pattern
- }
+ schemaDirectives,
});
export default schema;
diff --git a/schema.test.js b/schema.test.js
index 39962d1..5b92244 100644
--- a/schema.test.js
+++ b/schema.test.js
@@ -1,5 +1,6 @@
import { addMocksToSchema } from "@graphql-tools/mock";
-import schema from "./schema";
+import { SchemaDirectiveVisitor } from '@graphql-tools/utils';
+import schema, { schemaDirectives } from "./schema";
import { graphql } from "graphql";
import { ValidateDirectiveVisitor } from "@profusion/apollo-validation-directives";
@@ -14,6 +15,7 @@ beforeAll(() => {
preserveResolvers: false
});
+ SchemaDirectiveVisitor.visitSchemaDirectives(schemaWithMocks, schemaDirectives);
const schemaWithValidators = ValidateDirectiveVisitor.addValidationResolversToSchema(
schemaWithMocks
);
from apollo-validation-directives.
Related Issues (20)
- Unwanted validationErrors for null value on nullable type HOT 1
- Validation of nullable input field or argument HOT 5
- What is the license of this package? HOT 1
- Module fails if you're using apollo-server-core and not apollo-server HOT 3
- Stack overflow when calling ValidateDirectiveVisitor.addValidationResolversToSchema() HOT 5
- usage with apollo-server-lambda HOT 5
- Usage with appolo-federation HOT 4
- unwanted `validationError` with nullable field when using @stringLength HOT 3
- validation adds `field: null` when field is not provided HOT 2
- Validation Field Name not available HOT 2
- Stack Overflow on input that has itself as a field
- How can set custom error message for directives ? HOT 8
- check if validation directives work at Apollo Gateway HOT 2
- type issue HOT 2
- Doesn't work with apollo server v3 HOT 8
- Make @hasPermissions not check permissions on input values when they are equal to the default value
- validationErrors in info argument? HOT 5
- Apollo 4 and GQL update
- More types and functions could also be exported by lib/index.js
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-validation-directives.