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

create-root-schema

v2.0.1

Published

> 🌿 Combines schemas and types to help you modularize your GraphQL service

Downloads

21

Readme

create-root-schema

🌿 Combines schemas and types to help you modularize your GraphQL service

GraphQL is awesome, but there isn't yet a standardized way to break up schemas in a way that makes sense. By enforcing a simple standard (exporting certain variables) on all your schema files, you can break the service up in a way that makes sense for your project.

We believe this system allows you to make very few boilerplate changes to extend your service while also being very explicit—we don't like unnecessary magic.

ℹ️ This is just a very thin wrapper extending/replacing makeExecutableSchema. See graphql-tools for more documentation.

Usage

All your schema files can export typeDefs, resolvers, and schemaDirectives. All are optional.

To add functionality, each file may:

// Example Users schema file
import { fetchUser, fetchUsers } from './users';

export const typeDefs = /* GraphQL */ `
  type User {
    lastSeen: Timestamp
    name: String
  }

  # Extend the root types to expose logic...
  extend type Query {
    user(id: ID!): User
    users: [User]
  }
`;

export const resolvers = {
  Query: {
    user: (_, { id }) => fetchUser(id),
    users: () => fetchUsers()
  }
};

Then, import the schema parts into a single file and create a root schema:

import {
  combineSchemaDefinitions,
  makeExecutableSchema
} from 'create-root-schema';

import * as device from './device';
import * as notification from './notification';
import * as user from './user';

// NOTE: Choose one of these options…

// - option 1: get the combined schema:
export default combineSchemaDefinitions([device, notification, user]);

// - option 2: both combine the schema and convert to an executable schema:
export default makeExecutableSchema([device, notification, user]);

Usage with apollo-server-express v2

// ./schemas/index.js
import { combineSchemaDefinitions } from 'create-root-schema';

import * as device from './device';
import * as notification from './notification';
import * as user from './user';

export default combineSchemaDefinitions([brand, device, notification, user]);
// ./index.js
import { ApolloServer, gql } from 'apollo-server-express';
import express from 'express';
import schema from './schemas';

const app = express();

const server = new ApolloServer(schema);

server.applyMiddleware({ app });

app.listen({ port: 4000 }, () =>
  console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`)
);

Usage with graphql-yoga

// ./schemas/index.js
import { combineSchemaDefinitions } from 'create-root-schema';

import * as device from './device';
import * as notification from './notification';
import * as user from './user';

export default combineSchemaDefinitions([brand, device, notification, user]);
import { GraphQLServer } from 'graphql-yoga';
import schema from './schemas';

const server = new GraphQLServer(schema);
server.start(() => console.log('Server is running on localhost:4000'));

Extra Options

This is just a thin wrapper around makeExecutableSchema. Any options passed as the second argument will be forwarded directly to makeExecutableSchema.

import { makeExecutableSchema } from 'create-root-schema';

// See `graphql-tools` docs for more information
makeExecutableSchema([...schemas], { allowUndefinedInResolve: false });

Install

With Yarn or npm installed, run:

yarn add create-root-schema

# ...or, if using `npm`
npm install create-root-schema

License

MIT