Skip to content

mikaelbr/graphql-node-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[WIP] graphql-node-import

Import .graphql and .gql files directly in Node. Access entire files, queries and fragments, making reusable structures. You can also import fragments from other GraphQL files.

This plays really well with the VSCode GraphQL extension where you can run queries and get code completions directly in your editor.

Currently very much Work In Progress

Usage

Using in node

node -r @mikaelb/graphql-node-import myFile.js

Or at the top of your entry file:

import "@mikaelb/graphql-node-import"; // This wil also include typings for the file types

// Or

require("@mikaelb/graphql-node-import");

Examples

Simple use

# query.gql
query {
  someField
  anotherField
}
import query from "./query.gql";

// using something like apollo client
client.query({
  query,
});

Multiple queries

# query.gql
query Foo {
  someField
}

query Bar {
  otherField
}
import { operations } from "./query.gql";

// using something like apollo client
client.query({
  query: operations.Foo,
});
client.query({
  query: operations.Bar,
});

Using fragments

# fragments.gql
fragment fragName on SomeType {
  someField
}
import { fragments } from "./fragments.gql";
import gql from "graphql-tag";

const query = qgl`
query {
  ...fragName
}
${fragments.fragName}
`;

// using something like apollo client
client.query({
  query: operations.Foo,
});
client.query({
  query: operations.Bar,
});

About

Import `.graphql` and `.gql` files directly in Node, accessing queries and fragments

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published