如何结合使用 graphql 模块和 graphql 指令

问题描述 投票:0回答:1

我使用模块创建 graphql Yoga 服务器:

const application = createApplication({ modules: MY_MODULES_ARRAY })

const yoga = createYoga<ServerContext>({
    ...
    plugins: [useGraphQLModules(application)]
    ...
})

根据指令指南,我需要修补架构: https://the-guild.dev/graphql/tools/docs/schema-directives

我应该如何组合指令和模块?

我应该从

application.schema
获取架构,对其进行修补,然后使用新的修补架构而不是模块
createYoga()
吗?

graphql graphql-yoga graphql-modules
1个回答
0
投票

要在 graphql 模块的情况下修补架构

schemaBuilder
需要在
createApplication()
中使用参数:

const application = createApplication({
    modules: MY_MODULES_ARRAY,
    schemaBuilder: ({ typeDefs, resolvers }) => {
        // Build the schema from modules
        let schema = makeExecutableSchema({
            typeDefs,
            resolvers: resolvers
        })

        // Apply the directive transformer, i.e. upperCaseDirective
        const patchedSchema = MY_DIRECTIVE_TRANSFORMER(schema);

        return patchedSchema;
    }
})

© www.soinside.com 2019 - 2024. All rights reserved.