Giter VIP home page Giter VIP logo

Comments (3)

craigmulligan avatar craigmulligan commented on June 23, 2024 1

Amazing thanks @cabelitos will try it out and report back.

from apollo-validation-directives.

craigmulligan avatar craigmulligan commented on June 23, 2024 1

Can confirm this is working as expected. Thanks for the help 🥇

from apollo-validation-directives.

cabelitos avatar cabelitos commented on June 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.