How to fetch data from an API using GraphQL in a React App Of course everyone is familiar with REST APIs, but there is another type of API that is becoming increasingly popular and that is the GraphQL API. GraphQL is a data query language for APIs. The significant difference between GraphQL APIs and REST APIs is that in a GraphQL API, we explicitly indicate in our query which specific data we want to fetch and request. In a REST API, we get back all the data from a url endpoint. Thus, GraphQL saves us some time by giving us more control over which data we want to request and receive from the API. The first time I encountered GraphQL was when I was learning how to create a Gatsby.js app; it uses GraphQL to access your app data. I’ve also attended a workshop where I learned how to build a GraphQL API using MongoDB and Node.js. Naturally, the next logical step in my GraphQL expedition would be to use GraphQL with a frontend library like, React. In this blog, ...
Intro This page will walk you through a series of GraphQL queries, each designed to demonstrate a particular feature of GraphQL. These examples will work on the real schema used on graphql-reference example . You can run this example locally to experiment and poke around the innards of the site! To get to the GraphiQL editor, go to localhost:8000/___graphql (that’s three underscores). You can also open the CodeSandbox version of the example site. For more background information, read about why Gatsby uses GraphQL and how to use GraphiQL in any Gatsby site. Basic queries Example: Site metadata Start with the basics, pulling up the site title from your gatsby-config.js ’s siteMetadata . Copy copy code to clipboard { site { siteMetadata { title } } } In the GraphiQL editor, try editing the query to include the description from siteMetadata . When typing in th...
Due to the increasing need for analytics in every company today, exporting data to CSV is a very important feature in apps today. So in this article, I will put you through how to easily generate CSV with Node.js and csvjson and upload it to AWS S3. To upload files to S3, we will need the aws-sdk express csvjson package from npm: npm i aws-sdk express csvjson Now we can start writing our actual code: Each header field specification: 1.Bucket: My Bucket name on the S3 server. 2.Key: My file path in which my CSV file will be save. 3.Body: Content of my CSV file. 4.ContentType: We will be using ‘text/csv’. S3 upload method returns error and data in callback, where the data field contains location, bucket and key of uploaded file. For complete API reference, refer their official docs . If you don’t get any error in the above snippet, your bucket should have the file. I hope you found this post useful and please do let me know in case of any question or query. If you like this po...
Comments
Post a Comment