Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@meltwater/mlabs-graphql
Advanced tools
Changelog
[7.0.0] / 2020-11-17
Readme
GraphQL client and server toolkit.
Consolidates core GraphQL modules into a single package to ensure version compatibility and maximize code reuse.
gql
, the graphql-tag, as the default import
from this module.Add this as a dependency to your project using npm with
$ npm install @meltwater/mlabs-graphql
or using Yarn with
$ yarn add @meltwater/mlabs-graphql
See the complete API documentation and working examples.
Import graphql-tag by default with
// import gql from 'graphql-tag' // instead of this use line below
import gql from '@meltwater/mlabs-graphql'
All GraphQL.js modules are reexported, e.g.,
// import { graphql, buildSchema } from 'graphql' // instead of this use line below
import { graphql, buildSchema } from '@meltwater/mlabs-graphql'
All GraphQL-tools modules are reexported, e.g.,
// import { makeExecutableSchema } from 'graphql-tools' // instead of this use line below
import { makeExecutableSchema } from '@meltwater/mlabs-graphql'
Create a GraphQL Client and run a query with
import createLogger from '@meltwater/mlabs-logger'
import { createClient } from '@meltwater/mlabs-graphql'
const client = createClient({
origin: 'https://example.com',
path: '/graphql',
log: createLogger()
})
const logQuery = async () => {
const { data } = await client.query(gql`{
__schema {
types {
name
}
}
}`)
console.log(data)
}
logQuery().catch(err => { console.log(err) })
Register each GraphQL Client and its dependencies in an Awilix container
import { createContainer, asValue } from 'awilix'
import createLogger from '@meltwater/mlabs-logger'
import { registerClients } from '@meltwater/mlabs-graphql'
const container = createContainer()
container.register({
log: asValue(createLogger()),
reqId: asValue(null)
})
registerClients(container, {
foo: {origin: 'https://example.com'},
bar: {origin: 'https://bar.example.com'}
})
const fooClient = container.resolve('fooClient')
const barClient = container.resolve('barClient')
Create and run a Koa GraphQL Apollo Server with
import Koa from 'koa'
import { koaGraphql } from '@meltwater/mlabs-graphql'
import { typeDefs, resolvers } from './schema'
const app = new Koa()
const graphqlRouter = koaGraphql({ typeDefs, resolvers })
app.use(graphqlRouter.routes())
app.use(graphqlRouter.allowedMethods())
app.listen()
Define typeDefs
and resolvers
that can use scoped dependencies
and use registerServer
to add them to the Awilix container.
Then, add a scoped container to the Koa ctx.state
and koaGraphql
will use the container to handle each request with an ApolloServer
scoped to that request.
import { createContainer, asValue } from 'awilix'
import createLogger from '@meltwater/mlabs-logger'
import { registerServer } from '@meltwater/mlabs-graphql'
import gqlModels from './models'
const container = createContainer()
container.register({
log: asValue(createLogger())
})
registerServer(container, gqlModels)
const app = new Koa()
app.use((ctx, next) => {
ctx.state.container = container.createScope()
return next()
})
const graphqlRouter = koaGraphql()
app.use(graphqlRouter.routes())
app.use(graphqlRouter.allowedMethods())
app.listen()
$ git clone https://github.com/meltwater/mlabs-graphql.git
$ cd mlabs-graphql
$ nvm install
$ yarn
Run each command below in a separate terminal window:
$ yarn run watch
$ yarn run test:watch
The mlabs-graphql source is hosted on GitHub. Clone the project with
$ git clone git@github.com:meltwater/mlabs-graphql.git
You will need Node.js with npm, Yarn, and a Node.js debugging client.
Be sure that all commands run under the correct Node version, e.g., if using nvm, install the correct version with
$ nvm install
Set the active version for each shell session with
$ nvm use
Install the development dependencies with
$ yarn
CircleCI should already be configured: this section is for reference only.
The following environment variables must be set on CircleCI:
NPM_TOKEN
: npm token for installing and publishing packages.NPM_TEAM
: npm team to grant read-only package access
(format org:team
, optional).CODECOV_TOKEN
: Codecov token for uploading coverage reports (optional).These may be set manually or by running the script ./.circleci/envvars.sh
.
Primary development tasks are defined under scripts
in package.json
and available via yarn run
.
View them with
$ yarn run
Lint, test, and transpile the production build to dist
with
$ yarn run dist
Release a new version using npm version
.
This will run all tests, update the version number,
create and push a tagged commit,
and trigger CircleCI to publish the new version to npm.
master
branch or any branch matching ver/*
.npm version
on a separate branch,
wait for the commit to pass any required checks,
then merge and push the changes to a release branch.See the full documentation on using examples.
View all examples with
$ yarn run example
Linting against the JavaScript Standard Style and JSON Lint is handled by gulp.
View available commands with
$ yarn run gulp --tasks
Run all linters with
$ yarn run lint
In a separate window, use gulp to watch for changes and lint JavaScript and JSON files with
$ yarn run watch
Automatically fix most JavaScript formatting errors with
$ yarn run format
Unit and integration testing is handled by AVA and coverage is reported by Istanbul and uploaded to Codecov.
.spec.js
.lib
alongside the tested module.test
.fixtures
.Watch and run tests on changes with
$ yarn run test:watch
If using AVA snapshot testing, update snapshots with
$ yarn run test:update
Generate a coverage report with
$ yarn run report
An HTML version will be saved in coverage
.
Create a breakpoint by adding the statement debugger
to the test
and start a debug session with, e.g.,
$ yarn run test:inspect lib/client.spec.js
Watch and restart the debugging session on changes with
$ yarn run test:inspect:watch lib/client.spec.js
The author and active contributors may be found in package.json
,
$ jq .author < package.json
$ jq .contributors < package.json
To submit a patch:
git checkout -b my-new-feature
).git commit -am 'Add some feature'
).git push origin my-new-feature
).This npm package is licensed under the MIT license.
This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright holder or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
FAQs
GraphQL client and server toolkit.
We found that @meltwater/mlabs-graphql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).