Coder Social home page Coder Social logo

Comments (2)

SylarChen avatar SylarChen commented on June 24, 2024

https://github.com/graphql-java-kickstart/graphql-java-servlet

from graphql-calculator.

dugenkui03 avatar dugenkui03 commented on June 24, 2024

下边示例参考了graphql-java-servlet的官方示例代码。集成步骤如下:

  1. 使用DefaultGraphQLSourceBuilder 创建 GraphQLSource
  2. 创建graphql-java-kickstart GraphQLConfiguration对象时所用的GraphQL引擎相关对象都使用GraphQLSource 对象中数据即可,主要有 queryExecutionStrategy、Instrumentation、GraphQLSchema 和 PreparsedDocumentProvider。

这是官方示例上添加计算能力的代码改动,完整代码见graphql-calculator-samples

    private GraphQLConfigurationProvider() {

        /**
         * step 1: 使用 graphql calculator 生成GraphQL计算执行引擎
         */
        DefaultGraphQLSourceBuilder graphqlSourceBuilder = new DefaultGraphQLSourceBuilder();
        GraphQLSource source = graphqlSourceBuilder
                .wrapperConfig(DefaultConfig.newConfig().build())
                // 原始 Schema
                .originalSchema(createSchema())
                // 建议使用 CalculatorDocumentCachedProvider 实现类
                .preparsedDocumentProvider(new DocumentParseAndValidationCache())
                .build();

        /**
         * step 2:
         *      创建 GraphQLConfiguration 用的 graphql相关对象,使用 'GraphQLSource source' 中的数据;
         *      主要有 queryExecutionStrategy、Instrumentation、GraphQLSchema 和 PreparsedDocumentProvider
         *
         */
        GraphQLQueryInvoker queryInvoker = GraphQLQueryInvoker.newBuilder()
                .withExecutionStrategyProvider(
                        new DefaultExecutionStrategyProvider(
                                source.getGraphQL().getQueryStrategy(),
                                source.getGraphQL().getMutationStrategy(),
                                source.getGraphQL().getSubscriptionStrategy()))
                // calculator source
                .withInstrumentation(source.getGraphQL().getInstrumentation())
                // calculator source
                .withPreparsedDocumentProvider(source.getGraphQL().getPreparsedDocumentProvider())
                .build();

        configuration = GraphQLConfiguration.
                        // calculator source
                        with(source.getWrappedSchema())
                .with(queryInvoker)
                .build();
    }

from graphql-calculator.

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.