SlideShare a Scribd company logo
1 of 3
Graph QL
shell
{TITLE}
Show open issues for https://github.com/
Issues from Organization: {organization.name}
); }; const Repository = ({ repository }) => (
In Repository: {repository.name}
{repository.issues.edges.map(issue => (
•{issue.node.title} ))}
); export default App; It’s a decent setup, but there was nothing to see about variables yet. You simply passed the argum
{TITLE}
Show open issues for https://github.com/
); } return (
Issues from Organization: {organization.name}
); }; const Repository = ({ repository }) => (
In Repository: {repository.name}
{repository.issues.edges.map(issue => (
•{issue.node.title} ))}
); export default App; Exercises # 1. Confirm your source code for the last section 2. Explore and add fields to your organ
Previously, you learned how to query data from GitHub’s GraphQL API using the Apollo Client. Once the client is set up with a configuration, you can use its query() method to
send a GraphQL query with optional variables . As you have learned, reading data with GraphQL is not everything, because there are mutations for writing data as well. In this
lesson, you are going to define a mutation to star a repository on GitHub. The Apollo Client instance sends the mutation, but at first, you have to define it. Environment
Variables Key: REACT_APP_GITHUB… Value: Not Speci ed... GITHUB_PERSONAL… Not Speci ed... const ADD_STAR = gql` mutation AddStar($repositoryId: ID!) {
addStar(input: { starrableId: $repositoryId }) { starrable { id viewerHasStarred } } } `; index.js The identifier for the repository is required, or GitHub’s GraphQL server wouldn’t
know which repository you want to star. In the next code snippet, the Apollo Client is used to star a specific GitHub repository with a given identifier. The identifier can be
retrieved by adding the id field to your repository node field in the query. We use the mutate() method on the Apollo Client to send the mutation in a mutation and variables
payload. Anything can be done with the result to fit our application, but in this case, the result is simply logged on the console. Environment Variables Key:
REACT_APP_GITHUB… Value: Not Speci ed... GITHUB_PERSONAL… Not Speci ed... client .mutate({ mutation: ADD_STAR, variables: { repositoryId:
'MDEwOlJlcG9zaXRvcnk2MzM1MjkwNw==', }, }) .then(console.log); The result should be encapsulated in an addStar object (the name of the mutation), which should reflect
exactly the objects and fields that you have defined in the mutation: starrable , id and viewerHasStarred . Run the code below to find out the result: Environment Variables Key:
REACT_APP_GITHUB… Value: Not Speci ed... GITHUB_PERSONAL… index.js .ed_required_keys .ed_keys Not Speci ed... import 'dotenv/config'; import 'cross-fetch/polyfill';
import ApolloClient, { gql } from 'apollo-boost'; const client = new ApolloClient({ uri: 'https://api.github.com/graphql', request: operation => { operation.setContext({ headers: {
authorization: 'Bearer ==GITHUB_PERSONAL_ACCESS_TOKEN==', }, }); }, }); const GET_REPOSITORIES_OF_ORGANIZATION = gql` query($organization: String!,
$cursor: String) { organization(login: $organization) { name url repositories( first: 5 orderBy: { direction: DESC, field: STARGAZERS } after: $cursor ) { edges { node {
...repository } } pageInfo { endCursor hasNextPage } } } } fragment repository on Repository { name url } `; client .query({ query: GET_REPOSITORIES_OF_ORGANIZATION,
variables: { organization: 'the-road-to-learn-react', cursor: undefined, }, }) // resolve first page .then(result => { const { pageInfo, edges } = result.data.organization.repositories;
const { endCursor, hasNextPage } = pageInfo; console.log('second page', edges.length); console.log('endCursor', endCursor); return pageInfo; }) // query second page .then(({
endCursor, hasNextPage }) => { if (!hasNextPage) { throw Error('no next page'); } } return client.query({ query: GET_REPOSITORIES_OF_ORGANIZATION, variables: {
organization: 'the-road-to-learn-react', cursor: endCursor, }, }); }) // resolve second page .then(result => { const { pageInfo, edges } = result.data.organization.repositories; const {
endCursor, hasNextPage } = pageInfo; console.log('second page', edges.length); console.log('endCursor', endCursor); return pageInfo; }) // log error when there is no next
page .catch(console.log); const ADD_STAR = gql` mutation AddStar($repositoryId: ID!) { addStar(input: { starrableId: $repositoryId }) { starrable { id viewerHasStarred } } } `;
client .mutate({ mutation: ADD_STAR, variables: { repositoryId: 'MDEwOlJlcG9zaXRvcnk2MzM1MjkwNw==', }, }) .then(console.log); You’ve just learned how to use Apollo
Client only without any view-layer library. This is to avoid confusing the features of Apollo Client and React Apollo. Remember, Apollo Client can be used as a standalone
GraphQL client without connecting it to a view-layer like React, though it may seem a bit dull to see the data only on the console. We’ll see how Apollo connects the data-layer
to a React view-layer in the next chapter. Exercise # 1. Confirm your source code for the last section

More Related Content

Similar to Graph QL tuuneling secure via tcp dump into socket

Higher Order Components and Render Props
Higher Order Components and Render PropsHigher Order Components and Render Props
Higher Order Components and Render PropsNitish Phanse
 
Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"Fwdays
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Tsuyoshi Yamamoto
 
GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0Tobias Meixner
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptSeok-joon Yun
 
Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!Julien Truffaut
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed versionBruce McPherson
 
Recompacting your react application
Recompacting your react applicationRecompacting your react application
Recompacting your react applicationGreg Bergé
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineRoman Kirillov
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0Eyal Vardi
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript FunctionsColin DeCarlo
 
Should be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdfShould be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdffashionscollect
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09Daniel Bryant
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!Sébastien Levert
 
Apollo. The client we deserve
Apollo. The client we deserveApollo. The client we deserve
Apollo. The client we deserveYuri Nezdemkovski
 

Similar to Graph QL tuuneling secure via tcp dump into socket (20)

Higher Order Components and Render Props
Higher Order Components and Render PropsHigher Order Components and Render Props
Higher Order Components and Render Props
 
Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!Implicit parameters, when to use them (or not)!
Implicit parameters, when to use them (or not)!
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
 
Recompacting your react application
Recompacting your react applicationRecompacting your react application
Recompacting your react application
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0Http Communication in Angular 2.0
Http Communication in Angular 2.0
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Should be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdfShould be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdf
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
 
Advanced redux
Advanced reduxAdvanced redux
Advanced redux
 
SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!SharePoint Conference 2018 - APIs, APIs everywhere!
SharePoint Conference 2018 - APIs, APIs everywhere!
 
Apollo. The client we deserve
Apollo. The client we deserveApollo. The client we deserve
Apollo. The client we deserve
 
Graphql, REST and Apollo
Graphql, REST and ApolloGraphql, REST and Apollo
Graphql, REST and Apollo
 

Recently uploaded

Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 

Graph QL tuuneling secure via tcp dump into socket

  • 2. {TITLE} Show open issues for https://github.com/ Issues from Organization: {organization.name} ); }; const Repository = ({ repository }) => ( In Repository: {repository.name} {repository.issues.edges.map(issue => ( •{issue.node.title} ))} ); export default App; It’s a decent setup, but there was nothing to see about variables yet. You simply passed the argum {TITLE} Show open issues for https://github.com/ ); } return ( Issues from Organization: {organization.name} ); }; const Repository = ({ repository }) => ( In Repository: {repository.name} {repository.issues.edges.map(issue => ( •{issue.node.title} ))} ); export default App; Exercises # 1. Confirm your source code for the last section 2. Explore and add fields to your organ
  • 3. Previously, you learned how to query data from GitHub’s GraphQL API using the Apollo Client. Once the client is set up with a configuration, you can use its query() method to send a GraphQL query with optional variables . As you have learned, reading data with GraphQL is not everything, because there are mutations for writing data as well. In this lesson, you are going to define a mutation to star a repository on GitHub. The Apollo Client instance sends the mutation, but at first, you have to define it. Environment Variables Key: REACT_APP_GITHUB… Value: Not Speci ed... GITHUB_PERSONAL… Not Speci ed... const ADD_STAR = gql` mutation AddStar($repositoryId: ID!) { addStar(input: { starrableId: $repositoryId }) { starrable { id viewerHasStarred } } } `; index.js The identifier for the repository is required, or GitHub’s GraphQL server wouldn’t know which repository you want to star. In the next code snippet, the Apollo Client is used to star a specific GitHub repository with a given identifier. The identifier can be retrieved by adding the id field to your repository node field in the query. We use the mutate() method on the Apollo Client to send the mutation in a mutation and variables payload. Anything can be done with the result to fit our application, but in this case, the result is simply logged on the console. Environment Variables Key: REACT_APP_GITHUB… Value: Not Speci ed... GITHUB_PERSONAL… Not Speci ed... client .mutate({ mutation: ADD_STAR, variables: { repositoryId: 'MDEwOlJlcG9zaXRvcnk2MzM1MjkwNw==', }, }) .then(console.log); The result should be encapsulated in an addStar object (the name of the mutation), which should reflect exactly the objects and fields that you have defined in the mutation: starrable , id and viewerHasStarred . Run the code below to find out the result: Environment Variables Key: REACT_APP_GITHUB… Value: Not Speci ed... GITHUB_PERSONAL… index.js .ed_required_keys .ed_keys Not Speci ed... import 'dotenv/config'; import 'cross-fetch/polyfill'; import ApolloClient, { gql } from 'apollo-boost'; const client = new ApolloClient({ uri: 'https://api.github.com/graphql', request: operation => { operation.setContext({ headers: { authorization: 'Bearer ==GITHUB_PERSONAL_ACCESS_TOKEN==', }, }); }, }); const GET_REPOSITORIES_OF_ORGANIZATION = gql` query($organization: String!, $cursor: String) { organization(login: $organization) { name url repositories( first: 5 orderBy: { direction: DESC, field: STARGAZERS } after: $cursor ) { edges { node { ...repository } } pageInfo { endCursor hasNextPage } } } } fragment repository on Repository { name url } `; client .query({ query: GET_REPOSITORIES_OF_ORGANIZATION, variables: { organization: 'the-road-to-learn-react', cursor: undefined, }, }) // resolve first page .then(result => { const { pageInfo, edges } = result.data.organization.repositories; const { endCursor, hasNextPage } = pageInfo; console.log('second page', edges.length); console.log('endCursor', endCursor); return pageInfo; }) // query second page .then(({ endCursor, hasNextPage }) => { if (!hasNextPage) { throw Error('no next page'); } } return client.query({ query: GET_REPOSITORIES_OF_ORGANIZATION, variables: { organization: 'the-road-to-learn-react', cursor: endCursor, }, }); }) // resolve second page .then(result => { const { pageInfo, edges } = result.data.organization.repositories; const { endCursor, hasNextPage } = pageInfo; console.log('second page', edges.length); console.log('endCursor', endCursor); return pageInfo; }) // log error when there is no next page .catch(console.log); const ADD_STAR = gql` mutation AddStar($repositoryId: ID!) { addStar(input: { starrableId: $repositoryId }) { starrable { id viewerHasStarred } } } `; client .mutate({ mutation: ADD_STAR, variables: { repositoryId: 'MDEwOlJlcG9zaXRvcnk2MzM1MjkwNw==', }, }) .then(console.log); You’ve just learned how to use Apollo Client only without any view-layer library. This is to avoid confusing the features of Apollo Client and React Apollo. Remember, Apollo Client can be used as a standalone GraphQL client without connecting it to a view-layer like React, though it may seem a bit dull to see the data only on the console. We’ll see how Apollo connects the data-layer to a React view-layer in the next chapter. Exercise # 1. Confirm your source code for the last section