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

@fabien0102/graphql-import

v0.7.0

Published

[![CircleCI](https://circleci.com/gh/prismagraphql/graphql-import.svg?style=shield)](https://circleci.com/gh/prismagraphql/graphql-import) [![npm version](https://badge.fury.io/js/graphql-import.svg)](https://badge.fury.io/js/graphql-import)

Downloads

2

Readme

graphql-import

CircleCI npm version

Import & export definitions in GraphQL SDL (also refered to as GraphQL modules)

There is also a graphql-import-loader for Webpack available.

Install

yarn add graphql-import

Usage

import { importSchema } from 'graphql-import'
import { makeExecutableSchema } from 'graphql-tools'

const typeDefs = importSchema('schema.graphql')
const resolvers = {}

const schema = makeExecutableSchema({ typeDefs, resolvers })

Examples

Importing specific fields

Assume the following directory structure:

.
├── a.graphql
├── b.graphql
└── c.graphql

a.graphql

# import B from "b.graphql"

type A {
  # test 1
  first: String
  second: Float
  b: B
}

b.graphql

# import C from 'c.graphql'

type B {
  c: C
  hello: String!
}

c.graphql

type C {
  id: ID!
}

Running console.log(importSchema('a.graphql')) produces the following output:

type A {
  first: String
  second: Float
  b: B
}

type B {
  c: C
  hello: String!
}

type C {
  id: ID!
}

Extending root fields

It is possible to import from a root field like Query;

queries.graphql

type Query {
  feed: [Post!]!
  drafts: [Post!]!
}

mutations.graphql

type Mutation {
  publish(id: ID!): Post!
  deletePost(id: ID!): Post!
}

schema.graphql

# import Query.* from "queries.graphql"
# import Mutation.publish from "mutations.graphql"

Running console.log(importSchema('schema.graphql')) produces the following output:

type Query {
  feed: [Post!]!
  drafts: [Post!]!
}

type Mutation {
  publish(id: ID!): Post!
}

Importing with globs

You can also import every .graphql files in your project using globs patterns.

Assume the following directory structure:

.
├── a.graphql
├── b.graphql

a.graphql

type Query {
  first: String!
  second: Float
}

b.graphql

type Book {
  id: ID!
  name: String
  read: Boolean!
}

type Query {
  book(id: ID!): Book
}

type Mutation {
  readBook(id: ID!): Book
}

Running console.log(importSchema('*.graphql')) produces the following output:

type Query {
  first: String!
  second: Float
  book(id: ID!): Book
}

type Mutation {
  readBook(id: ID!): Book
}

type Book {
  id: ID!
  name: String
  read: Boolean!
}

Please refer to src/index.test.ts for more examples.

Development

The implementation documentation documents how things are implemented under the hood. You can also use the VSCode test setup to debug your code/tests.

Related topics & next steps

  • Static import step as build time
  • Namespaces
  • Support importing from HTTP endpoints (or Links)
  • Create RFC to add import syntax to GraphQL spec