bettermode-graphql-client
v1.0.5
Published
A typescript client to interact with the Bettermode GraphQL API.
Readme
Bettermode GraphQL Client
A typescript client to interact with the Bettermode GraphQL API.
How to use
Basic Usage
you can provide graphql url and token as options to the client.
import { BettermodeClient } from 'bettermode-graphql-client/client'
const t = new BettermodeClient({
graphqlUrl: 'localhost:4000/graphql',
accessToken: '<your-access-token>',
})or you can set the url in the environment variable BETTERMODE_GQL_ENDPOINT.
export BETTERMODE_GQL_ENDPOINT=http://localhost:4000const t = new BettermodeClient({
accessToken?: '<your-access-token>',
})you can also set the token per request.
const t = new BettermodeClient({
graphqlUrl?: 'localhost:4000',
})
t.network.get('basic', accessToken: '<your-access-token>')App Usage
To use the client in an app, you need to provide
clientId and clientSecret when initializing BettermodeClient.
Then you can use generateToken to generate a token
per network by providing networkId to make queries.
In case you want to act as a member you can provide memberId
to generateToken.
const t = new BettermodeClient({
graphqlUrl: 'https://api.bettermode.com',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
})
t.generateToken({
networkId: '<your-network-id>',
memberId: '<acting-member-id>',
}).then(token => {
// you can set the token globally
t.setToken(token)
// or use it per request
t.network.get('basic', token)
})