# graphql-import-files

> Light and easy package that will load .graphql files and use them with syntax highlighting.

Latest version **1.6.0** (published 2025-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-import-files
pnpm add graphql-import-files
yarn add graphql-import-files
bun add graphql-import-files
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2025-10-01 |
| First published | 2020-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | Tiago Santos Da Silva |
| Maintainers | tiagosilva |
| Keywords | graphql-import-files, graphql-import, graphql import, graphql-require-files, graphql-require, graphql require, graphql schema, graphql apollo schema, graphql gql, gql, graphql |

## Links

- npm: https://www.npmjs.com/package/graphql-import-files
- Repository: https://github.com/tiago154/graphql-import-files
- Homepage: https://github.com/tiago154/graphql-import-files#readme
- Issues: https://github.com/tiago154/graphql-import-files/issues
- npm.io page: https://npm.io/package/graphql-import-files

## Dependencies (3)

- [graphql](https://npm.io/package/graphql.md) ^16.8.1
- [fast-glob](https://npm.io/package/fast-glob.md) ^3.3.1
- [@graphql-tools/merge](https://npm.io/package/@graphql-tools/merge.md) ^9.0.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.6.0 (latest) — 2025-10-01
- 1.5.2 — 2024-10-06
- 1.5.1 — 2024-10-06
- 1.5.0 — 2024-10-06
- 1.4.0 — 2024-10-06
- 1.3.0 — 2023-10-05
- 1.2.19 — 2023-01-09
- 1.2.18 — 2022-10-15
- 1.1.18 — 2022-10-01
- 1.0.18 — 2022-02-03
- 1.0.17 — 2021-09-19
- 1.0.16 — 2021-09-19
- 1.0.15 — 2021-08-23
- 1.0.14 — 2021-08-23
- 1.0.13 — 2021-08-12
- … 15 more at https://npm.io/package/graphql-import-files/versions

## README

<div align="center">

[![npm](https://img.shields.io/npm/dy/graphql-import-files?color=%2303a1fc&style=for-the-badge)](https://npm-stat.com/charts.html?package=graphql-import-files)

</div>

<div align="center">

[![Build Status](https://travis-ci.com/tiago154/graphql-import-files.svg?branch=master)](https://travis-ci.com/tiago154/graphql-import-files)
[![Coverage Status](https://coveralls.io/repos/github/tiago154/graphql-import-files/badge.svg)](https://coveralls.io/github/tiago154/graphql-import-files)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tiago154/graphql-import-files)
[![Npm Version](https://img.shields.io/npm/v/graphql-import-files.svg)](https://www.npmjs.com/package/graphql-import-files)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/tiago154/graphql-import-files)

</div>

# graphql-import-files
Light and easy package that will load .graphql files and use them with syntax highlighting.

## Install

```sh
npm i -S graphql-import-files
```

## Usage:

## Loading a single file

For example, your files and folders look like this:

```
root
├──src
  ├──index.js
  ├──schema
    ├──schema.graphql
```
Use the function ``loadFile`` that will load a single file.

```js
// index.js
const { ApolloServer } = require('apollo-server')
const { loadFile } = require('graphql-import-files')
const resolvers = require('./resolvers')

const server = new ApolloServer({
  typeDefs: loadFile('./schema/schema.graphql'), // Always consider the path at the root of the project
  resolvers
})

server.listen().then(({ url }) => {
  console.log(`Running on ${url}`)
})
```

**The `loadFile` function supports the `#import` annotation and this will allow you to load other files as if it were the import in a js file.**

```
root
├──src
  ├──index.js
  ├──schema
    ├──schema.graphql
    ├──user
      ├──user.graphql
    ├──location
      ├──location.graphql
```

./src/schema/schema.graphql
```graphql
#import './user/user.graphql'
#import './location/location.graphql'

type Query {
  user(id: ID!): User
  location(id: ID!): Location
}
```

./src/schema/user/user.graphql
```graphql
type User {
  id: ID!
  name: String!
}
```

./src/schema/location/location.graphql
```graphql
type Location {
  id: ID!
  name: String!
}
```

```js
// index.js
// ...
const { loadFile } = require('graphql-import-files')

const server = new ApolloServer({
  typeDefs: loadFile('./schema/schema.graphql'), // Always consider the path at the root of the project
  resolvers
})
// ...
```

## Loading multiple files

For example, your files and folders look like this:

```
root
├──src
  ├──index.js
  ├──schemas
    ├──query.graphql
    ├──user
      ├──user.gql
      ├──role.gql
    ├──product
      ├──product.graphql
```

Use the function ``loadFiles`` that will load multiple files.

```js
// index.js
const { ApolloServer } = require('apollo-server')
const { loadFiles } = require('graphql-import-files')
const resolvers = require('./resolvers')

const server = new ApolloServer({
  typeDefs: loadFiles('**/schemas/**/*.{graphql,gql}'), // Use the glob pattern to find multiple files
  resolvers
})

server.listen().then(({ url }) => {
  console.log(`Running on ${url}`)
})
```

---
_Source: https://npm.io/package/graphql-import-files · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
