Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
.gql or .graphql file types with Node

I'm using Apollo's graphql-server-express with Node and I would like to turn my "typedef" schema definition files into .graphql or .gql files for clarity and syntax highlighting.

What is the best way to do this? I cannot find any good resources online beyond Babel(?) which seems to be the only choice.

Thanks so much for the help!

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I'm sure you found solution so far, but for others this might be helpful https://github.com/prismagraphql/graphql-import .

Usage

import { importSchema } from 'graphql-import'
import { makeExecutableSchema } from 'graphql-tools'

const typeDefs = importSchema('schema.graphql')
const resolvers = {}

const schema = makeExecutableSchema({ typeDefs, resolvers })

Examples

Importing specific fields

Assume the following directory structure:

.
├── a.graphql
├── b.graphql
└── c.graphql

a.graphql

# import B from "b.graphql"

type A {
  # test 1
  first: String
  second: Float
  b: B
}

b.graphql

# import C from 'c.graphql'

type B {
  c: C
  hello: String!
}

c.graphql

type C {
  id: ID!
}
about 4 years ago · Santiago Trujillo Report

0

The schemas folder should have files with .graphql or .gql files

const path = require('path');
const { loadFilesSync } = require('@graphql-tools/load-files');
const { mergeTypeDefs } = require('@graphql-tools/merge');

const typesArray = loadFilesSync(path.join(__dirname, './schemas'));

module.exports = mergeTypeDefs(typesArray, { all: true });
about 4 years ago · Santiago Trujillo Report

0

Have a same question how to implement it in right way. Anyway this works for me.

import {gql} from 'apollo-server-express'
import * as types from './types.graphql'

export const typeDefs = gql`${types}`
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!