2.0.0 • Published 5 years ago
require-gql v2.0.0
Require GQL
This simple module allows you to "require" GQL files in Node.js in much the same way as you would any other .js or .json file.
Change Log
- v1.0.0 - Initial release
- v1.1.0
- Allow specifying GQL path relative to requiring (parent) module
- Allow for omitting
.gqlextension in path argument
- v1.1.1
- Fix module caching bug
- v1.1.2
- Improved detection of requiring module (hat-tip)
- v2.0.0
- Align with path reference patters for standard JS modules
Example
File structure
index.js
schema/
Book.gql
Query.gqlschema/Book.gql
# This "Book" type defines the queryable fields for every book in our data source.
type Book {
title: String
author: String
}schema/Query.gql
# The "Query" type is special: it lists all of the available queries that
# clients can execute, along with the return type for each. In this
# case, the "books" query returns an array of zero or more Books (defined above).
type Query {
books: [Book]
}index.js
'use strict';
const { requireGql } = require('require-gql');
const Book = requireGql('./schema/Book.gql');
const Query = requireGql('./schema/Query.gql');
console.log('Book:', Book);
console.log('Query:', Query);
/*
Book: {
kind: 'Document',
definitions: [
{
kind: 'ObjectTypeDefinition',
description: undefined,
name: [Object],
interfaces: [],
directives: [],
fields: [Array]
}
],
loc: { start: 0, end: 212 }
}
Query: {
kind: 'Document',
definitions: [
{
kind: 'ObjectTypeDefinition',
description: undefined,
name: [Object],
interfaces: [],
directives: [],
fields: [Array]
}
],
loc: { start: 0, end: 255 }
}
*/