.gql or .graphql file types with Node .gql or .graphql file types with Node express express

.gql or .graphql file types with Node


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!}


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 });


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}`