{"id":13393016,"url":"https://github.com/tiago154/graphql-import-files","last_synced_at":"2025-05-07T08:23:44.679Z","repository":{"id":42826528,"uuid":"237669769","full_name":"tiago154/graphql-import-files","owner":"tiago154","description":"Light and easy package that will load .graphql files and use them with syntax highlighting","archived":false,"fork":false,"pushed_at":"2023-10-18T12:14:43.000Z","size":992,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-16T18:23:40.795Z","etag":null,"topics":["apollo-server","gql","graphql","graphql-files","graphql-js","hacktoberfest","import","import-file","import-graph","light","syntax-highlighting"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tiago154.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-01T19:56:30.000Z","updated_at":"2024-05-30T06:29:28.597Z","dependencies_parsed_at":"2023-02-08T13:30:47.840Z","dependency_job_id":"2bb4c20e-fb53-44d3-b584-4f6f4e32ad1a","html_url":"https://github.com/tiago154/graphql-import-files","commit_stats":{"total_commits":71,"total_committers":2,"mean_commits":35.5,"dds":"0.14084507042253525","last_synced_commit":"93e40d2495ea67c3db2e467d86bd6621b742e41d"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiago154%2Fgraphql-import-files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiago154%2Fgraphql-import-files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiago154%2Fgraphql-import-files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiago154%2Fgraphql-import-files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiago154","download_url":"https://codeload.github.com/tiago154/graphql-import-files/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252840190,"owners_count":21812261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apollo-server","gql","graphql","graphql-files","graphql-js","hacktoberfest","import","import-file","import-graph","light","syntax-highlighting"],"created_at":"2024-07-30T17:00:41.107Z","updated_at":"2025-05-07T08:23:44.649Z","avatar_url":"https://github.com/tiago154.png","language":"TypeScript","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"\u003cdiv align=\"center\"\u003e\r\n\r\n[![npm](https://img.shields.io/npm/dy/graphql-import-files?color=%2303a1fc\u0026style=for-the-badge)](https://npm-stat.com/charts.html?package=graphql-import-files)\r\n\r\n\u003c/div\u003e\r\n\r\n\u003cdiv align=\"center\"\u003e\r\n\r\n[![Build Status](https://travis-ci.com/tiago154/graphql-import-files.svg?branch=master)](https://travis-ci.com/tiago154/graphql-import-files)\r\n[![Coverage Status](https://coveralls.io/repos/github/tiago154/graphql-import-files/badge.svg)](https://coveralls.io/github/tiago154/graphql-import-files)\r\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tiago154/graphql-import-files)\r\n[![Npm Version](https://img.shields.io/npm/v/graphql-import-files.svg)](https://www.npmjs.com/package/graphql-import-files)\r\n[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/tiago154/graphql-import-files)\r\n\r\n\u003c/div\u003e\r\n\r\n# graphql-import-files\r\nLight and easy package that will load .graphql files and use them with syntax highlighting.\r\n\r\n## Install\r\n\r\n```sh\r\nnpm i -S graphql-import-files\r\n```\r\n\r\n## Usage:\r\n\r\n## Loading a single file\r\n\r\nFor example, your files and folders look like this:\r\n\r\n```\r\nroot\r\n├──src\r\n  ├──index.js\r\n  ├──schema\r\n    ├──schema.graphql\r\n```\r\nUse the function ``loadFile`` that will load a single file.\r\n\r\n```js\r\n// index.js\r\nconst { ApolloServer } = require('apollo-server')\r\nconst { loadFile } = require('graphql-import-files')\r\nconst resolvers = require('./resolvers')\r\n\r\nconst server = new ApolloServer({\r\n  typeDefs: loadFile('./schema/schema.graphql'), // Always consider the path at the root of the project\r\n  resolvers\r\n})\r\n\r\nserver.listen().then(({ url }) =\u003e {\r\n  console.log(`Running on ${url}`)\r\n})\r\n```\r\n\r\n**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.**\r\n\r\n```\r\nroot\r\n├──src\r\n  ├──index.js\r\n  ├──schema\r\n    ├──schema.graphql\r\n    ├──user\r\n      ├──user.graphql\r\n    ├──location\r\n      ├──location.graphql\r\n```\r\n\r\n./src/schema/schema.graphql\r\n```graphql\r\n#import './user/user.graphql'\r\n#import './location/location.graphql'\r\n\r\ntype Query {\r\n  user(id: ID!): User\r\n  location(id: ID!): Location\r\n}\r\n```\r\n\r\n./src/schema/user/user.graphql\r\n```graphql\r\ntype User {\r\n  id: ID!\r\n  name: String!\r\n}\r\n```\r\n\r\n./src/schema/location/location.graphql\r\n```graphql\r\ntype Location {\r\n  id: ID!\r\n  name: String!\r\n}\r\n```\r\n\r\n```js\r\n// index.js\r\n// ...\r\nconst { loadFile } = require('graphql-import-files')\r\n\r\nconst server = new ApolloServer({\r\n  typeDefs: loadFile('./schema/schema.graphql'), // Always consider the path at the root of the project\r\n  resolvers\r\n})\r\n// ...\r\n```\r\n\r\n## Loading multiple files\r\n\r\nFor example, your files and folders look like this:\r\n\r\n```\r\nroot\r\n├──src\r\n  ├──index.js\r\n  ├──schemas\r\n    ├──query.graphql\r\n    ├──user\r\n      ├──user.gql\r\n      ├──role.gql\r\n    ├──product\r\n      ├──product.graphql\r\n```\r\n\r\nUse the function ``loadFiles`` that will load multiple files.\r\n\r\n```js\r\n// index.js\r\nconst { ApolloServer } = require('apollo-server')\r\nconst { loadFiles } = require('graphql-import-files')\r\nconst resolvers = require('./resolvers')\r\n\r\nconst server = new ApolloServer({\r\n  typeDefs: loadFiles('**/schemas/**/*.{graphql,gql}'), // Use the glob pattern to find multiple files\r\n  resolvers\r\n})\r\n\r\nserver.listen().then(({ url }) =\u003e {\r\n  console.log(`Running on ${url}`)\r\n})\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiago154%2Fgraphql-import-files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiago154%2Fgraphql-import-files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiago154%2Fgraphql-import-files/lists"}