Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kyleplump/moleculer-gql-client
https://github.com/kyleplump/moleculer-gql-client
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kyleplump/moleculer-gql-client
- Owner: kyleplump
- License: mit
- Created: 2023-06-21T21:15:37.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-07-10T20:17:20.000Z (over 1 year ago)
- Last Synced: 2024-06-16T21:36:31.505Z (5 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-moleculer - moleculer-gql-client - Mixin that allows Moleculer services to perform GraphQL requests (Services / Others)
README
# moleculer-gql-client
A wrapper of the [URQL](https://formidable.com/open-source/urql/) client, providing a GraphQL integration for the [Moleculer Framework](https://moleculer.services/)
## Features
- Queries
- Mutations
- Custom Headers
- Opt-in [Graphcache](https://formidable.com/open-source/urql/docs/graphcache/) support with optional custom [resolvers](https://formidable.com/open-source/urql/docs/graphcache/local-resolvers/)## 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](https://tldrlegal.com/license/mit-license).