Code Monkey home page Code Monkey logo

homework.graphql's Introduction

graphql

### This was created during my time as a [Code Chrysalis](https://codechrysalis.io) Student

GraphQL

1. Server Quick Start

Run yarn start to start the server.

Visit http://localhost:4000/graphql to test that the server is running.

Here are some queries you can test:

{
  pokemons {
    id
    name
  }
}
{
  pokemon(name: "Pikachu") {
    id
    name
  }
}

2. Schema

  • Right now, the server is only set up to provide the Pokemon's id and name. What if you also wanted to get their weight, attacks, and evolutions?

  • To do that, you will need to update the schema. The schema (in server/index.js) should model the full data object available. Take a look at server/data/pokemon.js to see what other fields you can add to the schema.

  • Update your schema so it fully represents your Pokemon data object!

  • Test your work! Go back to GraphiQL to test some queries. Remember, the magic of GraphQL is that you don't have to get back the full data object, even if it is available. Click Docs on the right side of the explorer to see your full schema.

3. Resolvers

  • The resolvers in server/index.js are functions that return the data requested in the queries. You will notice that the names of these functions match the names of the queries listed in the type Query in your schema.

  • This is where you can add additional types of resolvers. Think about what other types of queries you are interested in and add them here!

4. Mutations

  • If you want to add a mutation, the structure is a little different. Instead of using the keyword type, use the keyword input. Additionally, you will need to create a type called Mutation inside your schema. See below for an example!
input MessageInput {
  content: String
  author: String
}

type Message {
  id: ID!
  content: String
  author: String
}

type Query {
  getMessage(id: ID!): Message
}

type Mutation {
  createMessage(input: MessageInput): Message
  updateMessage(id: ID!, input: MessageInput): Message
}

5. Frontend

  • You can continue to test all of this using localhost:4000/graphql. But let's say you want to connect a frontend to this server. The only endpoint for your server is /graphql– if you are fetching a resource, you will need to POST your query to that endpoint (whether it is a query or a mutation). Suggestion: check out Apollo-Fetch or Apollo-Client.

Basic Requirements

  • Schema
    • Update your schema so it fully represents your Pokemon data object!
    • Add a Schema for Pokeballs! No need to have a full dataset, just pick some to include so you can play around. Include fields for at least:
      • Name
      • Effect
      • Catch Rate
  • Resolvers
    • Add Resolvers to Query Pokeballs you added in the last step.
  • Mutations
    • Create mutations to modify Pokemon and Pokeballs, including adding, editing and removing them
  • Frontend
    • Add a basic frontend that uses either apollo-client or apollo-fetch to query your endpoint.

Advanced Requirements

  • Add a React or Vue Frontend
  • Hook up a Database to store your data in

homework.graphql's People

Contributors

morita657 avatar mia-the-coding-cat 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.