Modularized Resolvers and TypeDefs - Error: typeDefs.reduce is not a function
See original GitHub issueI am trying to place resolvers and typeDefs in separate files using merge-graphql-schemas
. They are successfully merged however, I am getting this error when they reach new GraphQLServer({...})
. Any help would be appreciated.
Error
TypeError: typeDefs.reduce is not a function
at mergeTypeDefs (/[path...]/typeorm-demo/node_modules/graphql-yoga/src/index.ts:313:19)
Files
I have 2 .ts
resolvers and 2 .graphql
typeDefs formatted like:
#/resolvers/simple.resolver.ts
export default {
Query: {
beerMe: (_, { name }) => `Beer ${name || "Served"}`
}
};
#/typeDefs/simple.typeDef.graphql
type Query {
beerMe(name: String): String!
}
_#/typeDefs/index.ts
import * as path from "path";
import { fileLoader, mergeTypes } from "merge-graphql-schemas";
const typesArray = fileLoader(path.join(__dirname, "./"));
const typesMerged = mergeTypes(typesArray, { all: false });
console.log("typesMerged", typesMerged);
export default typesMerged;
#/resolvers/index.ts
import { mergeResolvers } from "merge-graphql-schemas";
import userResolver from "./user.resolvers";
import simpleResolver from "./simple.resolvers";
const resolversArray = [userResolver, simpleResolver];
const resolvers = mergeResolvers(resolversArray);
console.log("merged resolvers", resolvers);
export default resolvers;
#scr/index.ts
import "reflect-metadata";
import { createConnection } from "typeorm";
import { IResolvers } from "graphql-yoga/dist/src/types";
import { GraphQLServer } from "graphql-yoga";
const resolvers = require("./resolvers");
const typeDefs = require("./typeDefs");
const server = new GraphQLServer({ typeDefs, resolvers });
createConnection().then(() => {
server.start(() => console.log("Server is running on localhost:4000"));
});
Directory structure
__src
|____entity
| |____Profile.ts
| |____User.mysql-version.ts.bak
| |____User.ts
|____index.ts
|____resolvers
| |____index.ts
| |____simple.resolvers.ts
| |____user.resolvers.ts
|____typeDefs
| |____index.ts
| |____simple.typedefs.graphql
| |____user.typedefs.graphql
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Error: typeDefs.reduce is not a function · Issue #214 ... - GitHub
I am trying to place resolvers and typeDefs in separate files using merge-graphql-schemas. They are successfully merged however, ...
Read more >Modularizing your GraphQL schema code
But it turns out that we can arrange our schema and resolver code in ... schema.js const typeDefs = ` type Query {...
Read more >Exception: TypeError: graphqlAzureFunctions is not a function ...
1 Answer 1 ; ApolloServer } = require("apollo-server-azure-functions"); ; // Construct a schema, using GraphQL schema language const typeDefs = gql` ...
Read more >Dive Into GraphQL Part III: Building a GraphQL Server With ...
You'll see that thanks to the GraphQL tooling, it's not much harder than ... typeDefs, resolvers }); // proceed with the express app...
Read more >GraphQL Code Libraries, Tools and Services
const { data, errors } = await client.request(queryOrMutation); ... Split up your GraphQL resolvers in middleware functions. ... typeDefs,. resolvers,.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m on it. If it helps others remove that barrier, I’m glad to help.
@marktani Wanted to add more insight. Your provided
Object
tomergeTypeDefs
what is not supported. Currently is supportedstring
,array
,documentNode
. So maybe there should be some better error handling to show proper error. So there is missing check for array and if it’s not an array just throw error 😃 I can add it to my PR #220 and add it to documentation with this fix extra.