can't run apollo-server-express with merged typeDefs and resolvers using @graphql-tools/merge

413 Views Asked by At

hey friends this is the structure of my project and files down below: enter image description here

starting from app.js file:

import { Server } from "./src/Server";
import { config } from "dotenv";

config();

Server.StartServer();

Down below is the Server.ts file that is bootstrapping of the apollo-server-express

import express from "express";
import http from "http";
import { ApolloServer } from "apollo-server-express";
import { GraphQLServerOptions } from "apollo-server-core/src/graphqlOptions";
import { schema } from "./graphql/index";

export class Server {
  public static StartServer() {
    const app: express.Application = express();
    const server = new ApolloServer({
      schema,
      graphiql: true,
    } as unknown as GraphQLServerOptions);
    server.applyMiddleware({ app });
    const httpServer = http.createServer(app);
    server.installSubscriptionHandlers(httpServer);

    httpServer.listen(process.env.PORT, function () {
      console.log(`server is running on port ${process.env.PORT}`);
    });
  }
}

this is user.resolvers.ts file that my resolver goes here:

import { IResolvers } from "graphql-tools";

export const resolver: IResolvers = {
  Mutation: {
    register: function (parent, args, content, info) {
      console.log(parent);
    },
  },
  Query: {
    getUser: function (parent, args, content, info) {
      console.log(parent);
    },
  },
};

And here we go with the typeDef for in user.schema.ts file:

import { gql } from "apollo-server-express";
export const typeDef = gql`
    type User {
        username: String
        password: String
    }

    type Mutation {
        register(input: {username: String!, passwprd: String!})
    }

    type Query {
        getUSer(username): User
    }
`;

And finally over there in ./src/graphql/index.ts file I'm doing the mergig for resolvers and typeDefs there and I'm making the executableSchema for adding it to ApolloServer config object but I face the error below: enter image description here

Any Ideas and suggestions would be greatly appreciated. Early thanks for the contributors :)

0

There are 0 best solutions below