What is GraphQL?
- Type system for your data
- Define query language for your API
- Sever-side runtime for executing queries.
REST API versioning
- URI: ../map/version/2/buildings
- Accept header: Accept: application/vnd.myapi.v2 + json
- Customer request header: x-myAPIVersion-Header: 2
- URL parameter: ../maps/buildings?version=2
Add new fields and types to your GraphQL API without impacting existing queries. Aging fields can be deprecated and hidden from tools. By using a single evolving version, GraphQL APIs give apps continuous access to new features and encourage cleaner, more maintainable server code.
Apollo or Relay – GraphQL Client
What is GraphQL client?
Implement query and data caching to further optimize requests to GraphQL server. For new beginner, I recommend using Apollo first, short learning-curve and well documented.
Below image is some main comparison between Apollo and Relay.
Why using Apollo Client:
In general, we usually add “proxy” server (Nginx, nodeJs) for frontend application to send request and avoid CORS problem. But by using Apollo, it take over the proxy job and could interact with the GraphQL server directly.
React Component – Apollo Client example
- Using Apollo Client is so easy and fun when writing an react component. As example below, we define our channelsListQuery and pass it as parameter for graphql HOC component.
React component with Apollo Client – Channel list example
2. Then bootstrap your app. We need to create network interface for remote server and create an instance of ApolloClient. Then add a wrapper component of ApolloProvider.
2018 will be the GraphQL year, just give a try!