question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modularized Resolvers and TypeDefs - Error: typeDefs.reduce is not a function

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jboothecommented, Mar 22, 2018

I’m on it. If it helps others remove that barrier, I’m glad to help.

1reaction
huv1kcommented, Mar 22, 2018

@marktani Wanted to add more insight. Your provided Object to mergeTypeDefs what is not supported. Currently is supported string, 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found