Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

schema.graphql file can't be found (node graphql-yoga)

I am following the how to graphql tutorial where I am setting up a simple graphql server.

index.js

const { GraphQLServer } = require('graphql-yoga');

// 1
let links = [{
  id: 'link-0',
  url: 'www.howtographql.com',
  description: 'Fullstack tutorial for GraphQL'
}];

const resolvers = {
  Query: {
    info: () => `This is the API of a Hackernews Clone`,
    // 2
    feed: () => links,
  },
  // 3
  Link: {
    id: (parent) => parent.id,
    description: (parent) => parent.description,
    url: (parent) => parent.url,
  }
};

// 3
const server = new GraphQLServer({
  typeDefs:'./schema.graphql',
  resolvers,
});

server.start(() => console.log(`Server is running on http://localhost:4000`));

As you can see, I am referencing my schema file when creating the GraphQLServer. When I run the server, however, I am getting the following error:

/Users/BorisGrunwald/Desktop/programmering/Javascript/GraphQL/hackernews-node/node_modules/graphql-yoga/dist/index.js:418
                throw new Error("No schema found for path: " + schemaPath);
            ^

My file structure:

enter image description here

Can anyone spot the error?

like image 222
Boris Grunwald Avatar asked Sep 07 '25 16:09

Boris Grunwald


1 Answers

You gave the path ./schema.graphql which makes node look for the file in the directory where you run it instead of the correct location which is 'src/schema.graphql'.

So you need to change the path to:

//...
typeDefs: 'src/schema.graphql',
//...
like image 174
Viktor Nonov Avatar answered Sep 11 '25 06:09

Viktor Nonov