-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
graphql-tools/dist has no exported member 'addMocksToSchema'. #1616
Comments
https://www.apollographql.com/docs/graphql-tools/mocking/ is out-of-date. GraphQL Tools has a new website. You can find the up-to-date documentation there; |
Thanks a lot @ardatan It looks like I now have a very similar issue to #957 because I'm using apollo-server at the same time. According to your comment here #957 (comment), am I stuck? /node_modules/ts-node/src/index.ts:434
return new TSError(diagnosticText, diagnosticCodes)
^
TSError: ⨯ Unable to compile TypeScript:
server/graphql/index.ts:36:23 - error TS2322: Type 'typeof AuthDirective' is not assignable to type 'typeof SchemaDirectiveVisitor'.
Types of property 'visitSchemaDirectives' are incompatible.
Type '(schema: GraphQLSchema, directiveVisitors: Record<string, typeof SchemaDirectiveVisitor>, context?: Record<string, any>) => Record<...>' is not assignable to type '(schema: GraphQLSchema, directiveVisitors: { [directiveName: string]: typeof SchemaDirectiveVisitor; }, context?: { [key: string]: any; }) => { [directiveName: string]: SchemaDirectiveVisitor[]; }'.
Types of parameters 'directiveVisitors' and 'directiveVisitors' are incompatible.
Type '{ [directiveName: string]: typeof SchemaDirectiveVisitor; }' is not assignable to type 'Record<string, typeof SchemaDirectiveVisitor>'.
Index signatures are incompatible.
Type 'typeof import("node_modules/apollo-server-core/node_modules/graphql-tools/dist/schemaVisitor").SchemaDirectiveVisitor' is not assignable to type 'typeof import("node_modules/@graphql-tools/utils/SchemaDirectiveVisitor").SchemaDirectiveVisitor'.
Types of property 'visitSchemaDirectives' are incompatible.
Type '(schema: GraphQLSchema, directiveVisitors: { [directiveName: string]: typeof SchemaDirectiveVisitor; }, context?: { [key: string]: any; }) => { [directiveName: string]: SchemaDirectiveVisitor[]; }' is not assignable to type '(schema: GraphQLSchema, directiveVisitors: Record<string, typeof SchemaDirectiveVisitor>, context?: Record<string, any>) => Record<...>'.
Types of parameters 'directiveVisitors' and 'directiveVisitors' are incompatible.
Type 'Record<string, typeof SchemaDirectiveVisitor>' is not assignable to type '{ [directiveName: string]: typeof SchemaDirectiveVisitor; }'.
Index signatures are incompatible.
Type 'typeof import("node_modules/@graphql-tools/utils/SchemaDirectiveVisitor").SchemaDirectiveVisitor' is not assignable to type 'typeof import("node_modules/apollo-server-core/node_modules/graphql-tools/dist/schemaVisitor").SchemaDirectiveVisitor'.
Property 'getDeclaredDirectives' is protected but type 'SchemaDirectiveVisitor<TArgs, TContext>' is not a class derived from 'SchemaDirectiveVisitor'.
36 schemaDirectives: { auth: AuthDirective },
~~~~
at createTSError (node_modules/ts-node/src/index.ts:434:12)
at reportTSError (node_modules/ts-node/src/index.ts:438:19)
at getOutput (node_modules/ts-node/src/index.ts:578:36)
at Object.compile (node_modules/ts-node/src/index.ts:775:32)
at Module.m._compile (ts-node/src/index.ts:858:43)
at Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Object.require.extensions.<computed> [as .ts] (node_modules/ts-node/src/index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19) |
It is due to the conflict between an old version that uses Apollo and our new version. You can create your schema according to our documentation and pass the final schema to |
I think I'm already creating and passing the schema according to your documentation: import { makeExecutableSchema } from '@graphql-tools/schema';
import { addMocksToSchema } from '@graphql-tools/mock';
import { MockList } from '@graphql-tools/mock';
const typeDefs = importSchema(`${__dirname}/schema.graphql`)
const schema = makeExecutableSchema({
typeDefs,
resolvers
})
const mocks = {
Person: () =>({
summary: () => new MockList([0, 12]),
}),
}
addMocksToSchema({
schema,
mocks,
preserveResolvers: true
})
const server = new ApolloServer({
typeDefs,
resolvers,
schemaDirectives: { auth: AuthDirective },
playground: {
settings: {
"request.credentials": "same-origin"
}
},
formatError: err => {
log.error({ message: `GraphQL Error: ${err.message}`, stack_trace: err.stack });
// Don't give the specific errors to the client.
if (err.message === "Not authorized") {
return new Error("Not authorized");
}
// Otherwise return the original error. The error can also
// be manipulated in other ways, so long as it's returned.
return err;
},
context: context => {
const req = context.req as Request;
const { user } = req;
return { user };
}
}); and my schema has:
|
You are creating a schema with import { makeExecutableSchema } from '@graphql-tools/schema';
import { addMocksToSchema, MockList } from '@graphql-tools/mock';
const typeDefs = importSchema(`${__dirname}/schema.graphql`) // I am not sure where this comes from?
let schema = makeExecutableSchema({
typeDefs,
resolvers,
schemaDirectives: { auth: AuthDirective }, // << This is where `schemaDirectives` belongs to
})
const mocks = {
Person: () =>({
summary: () => new MockList([0, 12]),
}),
}
schema = addMocksToSchema({ // reassign the result, this function returns a new schema
schema,
mocks,
preserveResolvers: true
})
const server = new ApolloServer({
schema, // << Use generated schema here
playground: {
settings: {
"request.credentials": "same-origin"
}
},
formatError: err => {
log.error({ message: `GraphQL Error: ${err.message}`, stack_trace: err.stack });
// Don't give the specific errors to the client.
if (err.message === "Not authorized") {
return new Error("Not authorized");
}
// Otherwise return the original error. The error can also
// be manipulated in other ways, so long as it's returned.
return err;
},
context: context => {
const req = context.req as Request;
const { user } = req;
return { user };
}
}); |
@ardatan many thanks for your precious help on this, it now runs! All the best and thank you for your work |
const typeDefs = importSchema(`${__dirname}/schema.graphql`) // I am not sure where this comes from? Btw this line came from https://github.com/ardatan/graphql-import and I just saw I can migrate it to graphql-tools 👍 |
I'm trying to follow https://www.apollographql.com/docs/graphql-tools/mocking/ where they do:
But I get the following whereas my dependencies look up-to-date?
Here is my package.json
thanks
The text was updated successfully, but these errors were encountered: