Git Product home page Git Product logo

sahu-booking-apollographql's Introduction

Apollo GraphQL Server

Note, this repo follows up a companion video series on YouTube.

A demo chat GraphQL API built with apollo-server on top of Express.

ApolloServer class

apollo-server library exports a core class that you can instantiate with an options object.

new ApolloServer({
  typeDefs,
  resolvers,
  context,
  mocks,
  formatError,
  ...
})

In v1, typeDefs and resolvers were passed to makeExecutableSchema. The resulting schema would then be supplied to graphqlExpress middleware. In v2, ApolloServer only requires two arguments,

  • typeDefs (Object) to declare the data types with SDL, and
  • resolvers (Object) to resolve the schema with resolver functions

Some other optional arguments include

  • context (Object) to share data across resolvers
  • mocks (Boolean) to enable randomly-generated mocks
  • formatError (Object or Function) to fine-tune the error format
  • subscriptions (String or Object) to configure real-time updates
  • schema (Object) for backwards compatibility with v1

To see a full list of arguments, refer to apollo-server API.

Previously, typeDefs were written in SDL using a template literal, which didn't allow for syntax highlighting. As of v2, typeDefs are invoked on gql with a tagged template, and can be color coded with an editor extension (such as GraphQL for VSCode).

const typeDefs = gql`
  type Query {
    user(id: ID!): User
  }
`

resolvers, unlike rootValue in express-graphql, allow for root-level and nested resolvers. Each resolver function falls under Query, Mutation, Subscription, or custom object type, and has the following signature

const resolvers = {
  Query: {
    user: (root, args, context, info) => { /*...*/ }
  }
}

This is different from rootValue resolvers in express-graphql

const rootValue = {
  user: (args, context, info) => { /*...*/ }
}

In apollo-server, root evaluates to either the parent field, or rootValue for top-level resolvers. See its value differs depending on the field. As with express-graphql, any fields that are not defined explicitly will be accessed as object props or invoked as methods on the root.

sahu-booking-apollographql's People

Contributors

lamidoking avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.