Graphql Tools to Strucutre , Combine Resolvers , Merge Schema Definitions and generate schema file for Node.js / Next.Js / Graphql Apollo server
Topics
npm i fast-graphql
yarn add fast-graphql
-
Nex.js Advanced Graphql Crud MongoDB Starter - Starter Generic CRUD with Advanced Apollo Graphql server with Next.js and Mongodb (TypeScript)
-
https://github.com/idurar/next-js-graphql-apollo-server-starter
import { mergeSchemas } from 'fast-graphql';
const pathfiles = './backend/graphql/typeDefs/*.gql';
const mergedSchemas = mergeSchemas({ pathfiles });
export default mergedSchemas;
import { combineResolvers, resolverType } from 'fast-graphql';
import user from './user';
import place from './place';
import review from './review';
const resolvers: resolverType[] = [place, user, review];
const cominedResolvers = combineResolvers({ resolvers });
export default cominedResolvers;
./scripts/generateSchema.js
const { generateSchema } = require('fast-graphql');
const inputPath = './graphql/typeDefs/*.gql';
const schemaPath = './graphql/schema.graphql';
const typeDefsPath = './graphql/typeDefs/index.ts';
generateSchema({ inputPath, schemaPath, typeDefsPath });
# package.json
"scripts": {
"dev": "yarn generate && next dev",
...
"generate:schema": "node ./scripts/generateSchema"
},