npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gyu.nu/adonis-graphql

v1.0.1

Published

A GraphQL Provider for Adonis.js

Downloads

5

Readme

Gyunu Adonis GraphQL

This module's aim is to simplify the process of generating a GraphQL server on an AdonisJS installation.

It has peer dependencies for:
graph-ql
graphql-tools apollo-server-adonis

Install these with:

yarn add graph-ql graphql-tools apollo-server-adonis
npm i graph-ql graphql-tools apollo-server-adonis

Getting Stated

Installation

To get started, first install the package:
yarn add @gyu.nu/adonis-graphql
npm i @gyu.nu/adonis-graphql --save

Registration

Register the provider in start/app providers array, like all other providers with the following line:

'@gyu.nu/adonis-graphql/providers/GraphQLProvider',

Usage

Configuration

This step is important!

create a file in config called graphql.js and add the following to it:

'use strict'

const Env = use('Env')
const Helpers = use('Helpers')

module.exports = {
  path: 'app/Graphql',
  ext: '.gql',
  resolverExt: '.js',
  endpoints: {
    graphql: Env.get('GRAPHQL_ENDPOINT', '/graphql'),
    graphiql: Env.get('GRAPHQL_ENDPOINT', '/graphiql')
  }
}

Config Properties

path: property is the path where you keep all the .gql files (Types, Queries, Mutations, Input, Enums, Interfaces etc) which will get autoloaded by the provider

ext: The file extension used by your graphql specifications, if not using the .gql filetype

resolverExt: The extension of your resolver files, usually .js

endpoints: The endpoints to use for the graphql api, you can use env vars here like above. You can set them to be anything as long as they dont clash with other routes.


Registering Routes

Open up start.routes.js and require apollo-server-adonis like this:

const { graphqlAdonis, graphiqlAdonis } = require('apollo-server-adonis')

make sure const Route = use(Route) is above all the following.
use adonis-graphql by using it like so:

const graphql = use('GraphQL')

Then, define the handlers for the graphql and graphiql endpoints call the following methods:

graphql.handleGraphql(Route, graphqlAdonis)
graphql.handleGraphiql(Route, graphiqlAdonis)

and the routing for the graphql and graphiql endpoints, .gql files and resolvers will be automatically handled.

Thats it!

Run adonis and navigate to the graphiql endpoint set in config/graphql.js and you should see graphiql.

The handler functions expect the Route provider from adonis to set the routes, we pass it in so in the future we can use other routing if necessary.

The second argument is the graphql handler, in this case the graphqlAdonis package, but we can use any other by passing it in as long as it has the same interface.

This way, in the future this package can handle different frameworks or interfaces.


Extension

To pass in more default types and resolvers, the graphql instance returned by the provider exposes a use function.

Pass in an object with the keys: queries and/or resolvers, where those properties are an array of gql strings and normal js resolvers.

The provider will then load these along with the defaults. You can then move your queries and resolvers into other packages and just use them here.

example, using gyu.nu/adonis-graphql-typeext:

graphql.use(require('@gyu.nu/adonis-graphql-typeext'))

Use the use method before you call the routing, otherwise the schema will be generated without it.