1.0.0 • Published 3 years ago

workflow-2-module-assignment-3 v1.0.0

Weekly downloads
4
License
ISC
Repository
github
Last release
3 years ago

Workflow 2 Module Assignment 3

Install

To install parcel:

npm install -g parcel-bundler

npm init -y

npm i apollo-boost qraphql

Add

Add this file:

.gitignore

node_modules/

Add to js folder a script.js

Go to this link: https://graphqlzero.almansi.me

copy Get User`s Posts

Follow the link and past it in https://graphqlzero.almansi.me/api

Copy this to add to your script file:

import ApolloClient, { gql } from 'apollo-boost';

const client = new ApolloClient({
  uri: 'https://graphqlzero.almansi.me/api'
});
client.query({ query: gql`
  {
    user(id: 1) {
      id
      name
    }
  }
`}).then(console.log);

Change it to:

import ApolloClient, { gql } from 'apollo-boost';


const client = new ApolloClient({
  uri: 'https://graphqlzero.almansi.me/api'
});

client.query({ query: gql`
{
    user(id: 5) {
        posts {
          data {
            body
            title
          }
        }
      }
}
`}).then(console.log)

Parcel

add in your terminal:

parcel index.html

Level 1

Using the GraphQLZero API, make a request to get the posts of the user with an id of 5. Request only the title and body of each post.

Loop through the results and console log the title of each result.

To loop through and console.log each result

You have to loop trough inside the .then(), like this:

.then(json => {
    const titles = json.data.user.posts.data;

    titles.forEach(title => {
        console.log(title.title);
    })
});

Level 2

Turn your assignment into an NPM package and add the link to the README.

To install run:

npm i workflow-2-module-assignment-3