All Projects → smoketurner → Dropwizard Graphql

smoketurner / Dropwizard Graphql

Licence: apache-2.0
Dropwizard GraphQL Bundle

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Dropwizard Graphql

K2
Koa2 API template with passport, GraphQL, flowtype, knex and more.
Stars: ✭ 44 (-10.2%)
Mutual labels:  graphql
Graphql Tools Types
Custom Scalar Types for GraphQL-Tools
Stars: ✭ 46 (-6.12%)
Mutual labels:  graphql
Semantic Graphql
Create GraphQL schemas from RDF ontologies
Stars: ✭ 47 (-4.08%)
Mutual labels:  graphql
Magiql
🌐 💫 Simple and powerful GraphQL Client, love child of react-query ❤️ relay
Stars: ✭ 45 (-8.16%)
Mutual labels:  graphql
Graphql Advanced Projection
Fully customizable Mongoose/MongoDB projection generator.
Stars: ✭ 46 (-6.12%)
Mutual labels:  graphql
Githunt React
[DEPRECATED] 🔃 An example app frontend built with Apollo Client and React
Stars: ✭ 1,036 (+2014.29%)
Mutual labels:  graphql
Community
a community based on Node.js
Stars: ✭ 44 (-10.2%)
Mutual labels:  graphql
Parse Graphql
Parse GraphQL Query.
Stars: ✭ 49 (+0%)
Mutual labels:  graphql
Hunt Android
https://medium.com/@Cuong.Le/open-sourcing-hunt-d49919960ef1
Stars: ✭ 46 (-6.12%)
Mutual labels:  graphql
Graphql Kr.github.io
🇰🇷 GraphQL Document in Korean
Stars: ✭ 47 (-4.08%)
Mutual labels:  graphql
Omdb Graphql Wrapper
🚀 GraphQL wrapper for the OMDb API
Stars: ✭ 45 (-8.16%)
Mutual labels:  graphql
Graphql Retrofit Converter
A Retrofit 2 Converter.Factory for GraphQL.
Stars: ✭ 46 (-6.12%)
Mutual labels:  graphql
Graphql Scalars
A library of custom GraphQL Scalars for creating precise type-safe GraphQL schemas.
Stars: ✭ 1,023 (+1987.76%)
Mutual labels:  graphql
Graphql Factory
A toolkit for building GraphQL
Stars: ✭ 44 (-10.2%)
Mutual labels:  graphql
Graphql Zeus
GraphQL client and GraphQL code generator with GraphQL autocomplete library generation ⚡⚡⚡ for browser,nodejs and react native
Stars: ✭ 1,043 (+2028.57%)
Mutual labels:  graphql
Rdbms To Graphql
A Java CLI program that generates a GraphQL schema from a JDBC data source.
Stars: ✭ 44 (-10.2%)
Mutual labels:  graphql
Graphql Rails Generators
Graphql Rails Scaffold™. Automatically generate GraphQL types from your rails models.
Stars: ✭ 47 (-4.08%)
Mutual labels:  graphql
Graphql Query Test Mock
Easily mock GraphQL queries in your Relay Modern / Apollo / any-other-GraphQL-client tests.
Stars: ✭ 49 (+0%)
Mutual labels:  graphql
Umi Plugin Apollo
Apollo graphql plugin for umi
Stars: ✭ 48 (-2.04%)
Mutual labels:  graphql
Typeorm Graphql Loader
A query builder to easily resolve nested fields and relations for TypeORM-based GraphQL servers
Stars: ✭ 47 (-4.08%)
Mutual labels:  graphql

Dropwizard GraphQL Bundle

Build Status Maven Central GitHub license Become a Patron

A bundle for providing GraphQL API endpoints in Dropwizard applications.

Dependency Info

<dependency>
    <groupId>com.smoketurner.dropwizard</groupId>
    <artifactId>graphql-core</artifactId>
    <version>2.0.7-1</version>
</dependency>

Usage

Add a GraphQLBundle to your Application class.

@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
    // ...
    final GraphQLBundle<HelloWorldConfiguration> bundle = new GraphQLBundle<HelloWorldConfiguration>() {
        @Override
        public GraphQLFactory getGraphQLFactory(HelloWorldConfiguration configuration) {

            final GraphQLFactory factory = configuration.getGraphQLFactory();
            // the RuntimeWiring must be configured prior to the run()
            // methods being called so the schema is connected properly.
            factory.setRuntimeWiring(buildWiring(configuration));
            return factory;
        }
    };
    bootstrap.addBundle(bundle);
}

Adding GraphQL along with REST API Endpoints in Dropwizard

To use GraphQL along with REST APIs in dropwizard you need to change the root path in the bundle which we add in the main class of dropwizard. Otherwise the bundle may conflict with root path of REST API's.

You need to add the root path by overiding the initialize method in GraphQL bundle.

@Override
  public void initialize(Bootstrap<?> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/assets", "/", "index.htm", "graphql-playground"));
  }

This is the default initialize method in GraphQL bundle. If you want to expose your GraphQL endpoint at localhost:8080/graphql then you have to change the path in the AssetBundle constructor.

Now the overriden method which we add while adding bundle is

@Override
  public void initialize(Bootstrap<?> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/assets", "/graphql", "index.htm", "graphql-playground"));
    //graphql is the endpoint which is concerned with graphql
  }

This avoids conflict between REST API and GraphQL endpoints.

When we start the dropwizard server the GraphQL playground looks for GraphQL schema.GraphQL dropwizard creates a schema.json file after processing our GraphQL schema. The GraphQL playground looks out for this schema. It looks out at /graphql from the GraphQL endpoint.If you wish to change where the GraphQL playground looks for this schema file then you may override the run method in GraphQL bundle class.

If we want our schema.json to be available at localhost:8080/graphql/query then the overridden method should like this.

@Override
  public void run(final C configuration, final Environment environment) throws Exception {
    final GraphQLFactory factory = getGraphQLFactory(configuration);

    final PreparsedDocumentProvider provider =
        new CachingPreparsedDocumentProvider(factory.getQueryCache(), environment.metrics());

    final GraphQLSchema schema = factory.build();

    final GraphQLQueryInvoker queryInvoker =
        GraphQLQueryInvoker.newBuilder()
            .withPreparsedDocumentProvider(provider)
            .withInstrumentation(factory.getInstrumentations())
            .build();

    final graphql.kickstart.servlet.GraphQLConfiguration config =
        graphql.kickstart.servlet.GraphQLConfiguration.with(schema).with(queryInvoker).build();

    final GraphQLHttpServlet servlet = GraphQLHttpServlet.with(config);

    environment.servlets().addServlet("graphql", servlet).addMapping("/query", "/schema.json");
  }

Example Application

This bundle includes a modified version of the HelloWorldApplication from Dropwizard's Getting Started documentation.

You can execute this application on your local machine then running:

./mvnw clean package
java -jar graphql-example/target/graphql-example-2.0.7-2-SNAPSHOT.jar server graphql-example/hello-world.yml

This will start the application on port 8080 with a GraphQL Playground interface for exploring the API.

Support

Please file bug reports and feature requests in GitHub issues.

License

Copyright (c) 2020 Smoke Turner, LLC

This library is licensed under the Apache License, Version 2.0.

See http://www.apache.org/licenses/LICENSE-2.0.html or the LICENSE file in this repository for the full license text.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].