Skip to content

kyleplump/moleculer-gql-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

moleculer-gql-client

A wrapper of the URQL client, providing a GraphQL integration for the Moleculer Framework

Features

Install

npm install --save moleculer-gql-client moleculer

Settings

moleculer-gql-client offers the following service settings:

 settings: {
      gql: {
          uri: '',
          globalHeaders: {
          },
          enableGraphcache: false,
          graphcacheSettings: {
            resolvers: {}
          }
      }
    }

Usage

Call either the query or mutation action. An example of the query action:

const { ServiceBroker } = require("moleculer");
const GQLService = require("moleculer-graphql-client")

// Create a ServiceBroker
const broker = new ServiceBroker();

// Define a service
broker.createService({
    name: "gql",
    mixins: [GQLService],
    settings: {
      gql: {
          uri: 'https://swapi-graphql.netlify.app/.netlify/functions/index'
      }
    }
});

const request = `
  query Query {
    allFilms {
      films {
        title
        director
        releaseDate
        speciesConnection {
          species {
            name
            classification
            homeworld {
              name
            }
          }
        }
      }
    }
  }
`;


// Start the broker
broker.start()
  // Call the service
  .then(() => broker.call("gql.query", { request }))
  // Print the response
  .then(res => console.log("Result: ", res))
  .catch(err => console.error(`Error occured! ${err.message}`));

License

The project is available under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published