Code Monkey home page Code Monkey logo

graphql_boilerplate's Introduction

GraphQL Server for Raven's lower services

GraphQL API

requirements

  • nvm installed with node version 14.15.5

Make one query for all api endpoints from these lower microservices.

  • weather
  • mobile
  • transit

#Server : This is what we wil be using https://www.apollographql.com/docs/apollo-server/

#iOS https://www.apollographql.com/docs/ios/

#Android https://www.apollographql.com/docs/android/

#React https://www.apollographql.com/docs/react/

RUN THE APP

Running the app requires you to run an a node script

  • npm start

Visit http://localhost:3000/ and click on the button to query your service.

CURL commands

You MUST be on the network to have weather work, others will work without being on the network

  • run app

Weather Daily w/ day of week w/ moonPhase for that day

query{getWeatherDaily(zoneID:"54e4ffc9ceafc43649b4dae9",zipcode:"80104"){status,days{dayOfWeek,moonPhase}}}

POST curl --request POST --header 'content-type: application/json' --url http://localhost:3001/ --data '{"query":"{ getWeatherDaily(zoneID: "54e4ffc9ceafc43649b4dae9", zipcode: "80104") { status, days { dayOfWeek, moonPhase } }}"}'

GET curl --request GET --header 'content-type: application/json' --url http://localhost:3001/graphql?query=query%7BgetWeatherDaily%28zoneID:%2254e4ffc9ceafc43649b4dae9%22,zipcode:%2280104%22%29%7Bstatus,days%7BdayOfWeek,moonPhase%7D%7D%7D

StarWars Person

query{getStarWarsPerson(id:1){name}}

POST curl --request POST --header 'content-type: application/json' --url http://localhost:3001/ --data '{"query":"{ getStarWarsPerson(id:1) { name }}"}'

GET curl --request GET --header 'content-type: application/json' --url http://localhost:3001/graphql?query=query%7BgetStarWarsPerson%28id:1%29%7Bname%7D%7D

StarWars Planet : CUSTOM ERROR

query{getStarWarsPlanet(id:1){name}}

POST curl --request POST --header 'content-type: application/json' --url http://localhost:3001/ --data '{"query":"{ getStarWarsPlanet(id:1) { name }}"}'

GET curl --request GET --header 'content-type: application/json' --url http://localhost:3001/graphql?query=query%7BgetStarWarsPlanet%28id:1%29%7Bname%7D%7D

Session :

query{sessions{name}}

POST curl --request POST --header 'content-type: application/json' --url http://localhost:3001/ --data '{"query":"{ sessions{ title }}"}'

GET : // these can be cached curl --request GET --header 'content-type: application/json' --url http://localhost:3001/graphql?query=query%7Bsessions%7Btitle%7D%7D

Session + StarWars Person

query{sessions{title},getStarWarsPerson(id:1){name}}

POST curl --request POST --header 'content-type: application/json' --url http://localhost:3001/ --data '{"query":"{ sessions{ title },getStarWarsPerson(id:1) { name }}"}'

GET : // these can be cached curl --request GET --header 'content-type: application/json' --url http://localhost:3001/graphql?query=query%7Bsessions%7Btitle%7D,getStarWarsPerson%28id:1%29%7Bname%7D%7D

Helper Methods:

encode request for get

//encodeURI and encodeURIComponent do not encode encode parenthesis 
let graphQlQuery = 'query{sessions{title},getStarWarsPerson(id:1){name}}'
let queryStringForGetRequest = encodeURI(graphQlQuery).replace('(', "%28").replace(')', "%29")

Caching

Query limit: Although officially there is no limit specified by RFC 2616, many security protocols and recommendations state that maxQueryStrings on a server should be set to a maximum character limit of 1024. While the entire URL, including the querystring, should be set to a max of 2048 characters.

  • FIX: Send SHA-256 hash of query string to be executed

graphql_boilerplate's People

Watchers

Wes Duff avatar James Cloos 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.