Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

apollo graphql

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

//Define your GraphQL schema
const typeDefs = gql`
  type Book {
    title: String
    author: String
  }
  type Query {
    books: [Book]
  }
  // NOTE: please do not use any colon " : " or " , "
`;

  //Define your data set
const books = [
  {
    title: "The Awakening",
    author: "Kate Chopin",
  },
  {
    title: "City of Glass",
    author: "Paul Auster",
  },
];

//Define a resolver
const resolvers = {
  Query: {
    books: () => {
      return [books];
    },
  },
};

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

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

PREVIOUS NEXT
Code Example
Javascript :: puppeteer waitforselector 
Javascript :: Symbol Methods javascript 
Javascript :: javascript export multiple function 
Javascript :: set proxy for npm 
Javascript :: post object 
Javascript :: using sequelize to read from a table 
Javascript :: react state not updating immediately 
Javascript :: jsx full form 
Javascript :: how to get ip address and port from url in javascript 
Javascript :: sendgrid mail unique args 
Javascript :: js get data url of pdf 
Javascript :: angular firebase 
Javascript :: how to define width with [styles] in percentage in angular 
Javascript :: react add splite image 
Javascript :: error message to show in label jquery 
Javascript :: how to create object js 
Javascript :: update node two versions mac 
Javascript :: how to use jquery plugins in angular 8 
Javascript :: google drive show size folder 
Javascript :: radio button schema mongoose 
Javascript :: javascript how-do-i-check-whether-a-checkbox-is-checked-in-jquery 
Javascript :: example of call by value and call by reference in javascript 
Javascript :: what is tostring in js 
Javascript :: alphabetize text in javascript 
Javascript :: count number of times an element is occuring in an array in javascript 
Javascript :: javascript bounce animation 
Javascript :: js pop matched value in array 
Javascript :: Grunt--example gruntfile.js 
Javascript :: best way to setup nextjs project 
Javascript :: Show Modal Dialog on Jetpack Compose 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =