Skip to content

Commit

Permalink
Merge pull request #18 from xolvio/updates-graphql-tools
Browse files Browse the repository at this point in the history
feat: work with graphql-tools 6.x
  • Loading branch information
mbaranovski authored Jun 11, 2020
2 parents d578858 + 037f41d commit 56a165a
Show file tree
Hide file tree
Showing 5 changed files with 2,874 additions and 117 deletions.
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const {
buildOperationContext,
buildQueryPlan,
} = require("@apollo/gateway");
const { addMockFunctionsToSchema } = require("graphql-tools");
const { addResolversToSchema } = require("apollo-graphql");
const { addMocksToSchema, addResolversToSchema } = require("graphql-tools");
const { print } = require("graphql");
const {
buildFederatedSchema,
Expand Down Expand Up @@ -151,21 +150,28 @@ const setupSchema = serviceOrServices => {

function setupMocks(serviceMap, mocks) {
Object.values(serviceMap).forEach(service => {


let resolvers = {};
if (service.__addMocks__) {
console.log(service.schema)

Object.entries(mocks).forEach(([type, value]) => {
resolvers[type] = {
__resolveReference() {
return value();
}
};
});
addResolversToSchema(service.schema, resolvers);
addMockFunctionsToSchema({
console.log("MICHAL: mocks", mocks);
service.schema = addResolversToSchema(service.schema, resolvers);
service.schema = addMocksToSchema({
schema: service.schema,
preserveResolvers: true,
mocks
});
console.log("MICHAL: service.schema", service.schema);

}
});
}
Expand Down
Loading

0 comments on commit 56a165a

Please sign in to comment.