ardatan / graphql-import

Import & export definitions in GraphQL SDL
868 stars 56 forks source link

Error not a function? #588

Closed apaciuk closed 4 years ago

apaciuk commented 4 years ago

I am getting error with this, says importSchema is not a function?

const typeDefs = importSchema('./schema.graphql'); ^

TypeError: importSchema is not a function

Any tips on this at all?

Thanks

ardatan commented 4 years ago

Could you create a reproduction?

apaciuk commented 4 years ago

Hi yes all code is here, in the server express index file:

const express = require('express'); const { ApolloServer } = require('apollo-server-express'); const importSchema = require('graphql-import'); const makeExecutableSchema = require ('graphql-tools'); const graphqlHTTP = require('express-graphql');

const typeDefs = importSchema('./schema.graphql'); const resolvers = {}; const middleware = new graphqlHTTP();

const schema = makeExecutableSchema({ typeDefs, resolvers });

const server = new ApolloServer({ schema });

const app = express(); server.applyMiddleware({ app, middleware });

app.listen({ port: 4000 }, () => console.log(🚀 Server ready at http://localhost:4000${server.graphqlPath}) );

seems just the importSchema is not working, not a function

Thanks

ardatan commented 4 years ago

It's supposed to be const { importSchema } = require('graphql-import'); not const importSchema = require('graphql-import') It is a function inside the module.