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/
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.
You MUST be on the network to have weather work, others will work without being on the network
- run app
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
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
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
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
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
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")
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