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
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");
# query.gql
query {
someField
anotherField
}
import query from "./query.gql";
// using something like apollo client
client.query({
query,
});
# 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,
});
# 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,
});