This layer is completely agnostic to your data storage – you could have a file, an SQL database, a NoSQL database, or even an in-memory object like in this example – you just need to replace the resolve function on the GraphQLObjectType, which can also be async. I hope you have gotten a taste of the power of GraphQL. We can do the same as with any other GraphQL type and request only certain fields or load the related user. As we can see, the mutation returned the created shopping item. Now we have a way to query and update our data using GraphQL. CODE language-javascript keep-markup - const express = require("express") const graphqlHTTP = require("express-graphql") const GraphQLSchema = require("graphql").GraphQLSchema const app = express() app.use( "/graphql", graphqlHTTP( For this tutorial, we are going to create the /graphql route: This route receives a query with the structure of the data and returns a JSON object with the data in the requested structure. Express is a minimal and flexible node.js web application framework, providing a robust set of features for building single and multi-page, and hybrid web. The great thing about GraphQL is that you only need one route instead of the multitude of routes that we usually have in a REST API. Next, we need to create index.js, the entry point for our app and we need a route to call from our clients. We’ve just created a new Node project and installed Express and GraphQL. CODE language-bash keep-markup - mkdir GraphQLShopping cd GraphQLShoppingnpm init -ynpm install express express-graphql graphql
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |