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!
The GQL file type is primarily associated with BI/Query. GQL. File extension: GQL. File type: Data Model.
A GraphQL schema can contain more than just the scalar types. The two most used types are query and mutation types. Every GraphQL service will have a query type. This is the entry point to a GraphQL schema.
GraphQL comes with a set of default scalar types out of the box: Int : A signed 32‐bit integer. Float : A signed double-precision floating-point value. String : A UTF‐8 character sequence.
GraphQL is defined as a query language for client APIs and server-side runtime to execute those queries. That said, GraphQL is not exactly a language, but it has its own syntax and can be developed within several programming languages, such as Node. js.
I'm sure you found solution so far, but for others this might be helpful https://github.com/prismagraphql/graphql-import .
import { importSchema } from 'graphql-import'
import { makeExecutableSchema } from 'graphql-tools'
const typeDefs = importSchema('schema.graphql')
const resolvers = {}
const schema = makeExecutableSchema({ typeDefs, resolvers })
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 });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With