NodeJsGraphQL API with Node.js

GraphQL is an alternative to REST APIs that allows clients to request only the data they need. You can use libraries like Apollo Server to build a GraphQL API in Node.js.

npm install apollo-server graphql

const { ApolloServer, gql } = require('apollo-server');

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: () => 'Hello GraphQL!'
  }
};

const server = new ApolloServer({ typeDefs, resolvers });

server.listen(3000).then(({ url }) => {
  console.log(`GraphQL server ready at ${url}`);
});