logo

NJP

GraphQL Create an API Schema - Learn Integrations on the Now Platform

Import · Dec 04, 2023 · video

[Music] in this video we'll take a look at the major components of a graphql API schema the schema is simply text that describes what a client can request and how to request it at the top we have a schema block which contains two lines one for type query and one for type mutation it essentially defines what's coming later in the schema this block is always available by default and should not be modified as per the schema block we find type query this is where we Define the interface or the functions which a client can request and the way it interacts with that function here we see one called get game questions the parentheses indicate a single parameter named game ID of type ID the exclamation tells us that it's a mandatory field that makes sense because we need a society to retrieve a specific record in this case after the parenthesis is a colon and a return property in this first example we can tell it's an array of questions from the square brackets below that is another function named get game with a single mandatory parameter of type ID and returns a single game object although not seen here both question and game are types defined later in the schema if our API is going to offer the ability to create or update records will'll Define similar functions in the mutation block like this this one is called update game and accepts a number of parameters including a mandatory game ID and optional other parameters of different types we'll see how to pass these parameters from the query and access these parameters in the resolver video and upcoming demo in the sample schema we noted some data types of ID string and you may have even seen int these tell the API about the field or property types string and int are pretty easy to figure out representing string data and numbers or integers there are a few more that are useful to know like float for decimal numbers or Boolean for true and false the one that may be confusing at first is the ID data type this is a unique identifier much like a CIS ID or guid elsewhere on the platform it looks like a string works like a string but is easier to identify as an ID with the ID data type now that we have the basic understanding of the schema let's take a look at the next video where we'll see the resolvers the bits of serers side JavaScript that do the processing work hope you join me there

View original source

https://www.youtube.com/watch?v=sNJfUjCtKYo