1

I need help with custom directives when using graphql-modules library. Have no idea where to place my custom directives so it is combined with overall schema

1 Answer 1

1

I would like to post answer from Discord community, from user Maapteh.

here it the quote from him

in our app with old version we had everything in common module. We kept that approach partly when using the latest version of modules. See some parts of our codebase:

import { ApolloServer, SchemaDirectiveVisitor } from 'apollo-server-express';

const schema = AppModule.createSchemaForApollo();

SchemaDirectiveVisitor.visitSchemaDirectives(schema, { isMember: IsMemberDirective, deprecated: isDeprecated, ...SNIP... });

as you can see we create the schema we pass eventually to the apollo server (example using apollo). We add our generic directives like so. The schema for them is in our common module. Read further...

For common scalars we added a common module. With their schema (so in schema directory we also have the directives schemas) and their resolver.

const typeDefsArray = loadFilesSync(${__dirname}/schema/*.graphql, { useRequire: true, }); const typeDefs = mergeTypeDefs(typeDefsArray, { useSchemaDefinition: false });

const resolverFunctions = { ImageUrl: ImageUrlType, PageSize: PageSizeType, Date: DateResolver, ...SNIP... };

export const CommonModule = createModule({ id: 'common', typeDefs: typeDefs, resolvers: resolverFunctions, });

hope it helps you

https://discord.com/channels/625400653321076807/631489837416841253/832595211166548049

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.