/movieql

Movie API with Graphql

Primary LanguageJavaScript

movieql

Movie API with Graphql

Install

babel-node

]$ yarn global add babel-cli --ignore-engines
]$ yarn add babel-cli babel-preset-env babel-preset-stage-3 --dev

graphql-yoga

# https://github.com/prisma/graphql-yoga
]$ yarn add graphql-yoga

nodemon

]$ yarn global add nodemon

node-fetch

]$ yarn add node-fetch
OR
]$ yarn add axios

Config

packages.json

  "scripts": {
    "start": "nodemon --exec babel-node index.js"
  }

.babelrc

{
  "presets": ["env", "stage-3"]
}

Problems solved by GraphQL

# Over-fetching : Get all data that is not use.
# Under-fetching : Get not enough data. Request many times. Need to call many times to complete resource.

Can ask infomation what you want

schema

resolvers.js

// Resolve the Query(Nodejs do something to functionality)
const resolvers = {
  Query: {
    name: () => "nicolas",
  },
};

Query

type Query {
  // use ! when is required
  name: String!
}

Mutation

  type Mutation {
    addMovie(name: String!, score: Int!): Movie!
  }

Movie Rest Api