GraphQL Overview - Learn Integrations on the Now Platform
[Music] welcome to the section on graphql this series of short videos is intended to get you familiar with creating and using graphql apis on the N platform it covers both built-in apis and custom apis in this video I'll give you an overview of what graphql is and as a developer why you should care let's get started graph ql is an HTTP based protocol used to retrieve and modify data on a Target system sometimes known as a provider in much the same way as soap or rest does the advantage of graphql is that the payloads it transfers are generally much smaller so performance is improved and costs potentially reduced in many cases there's a single end point to an API since the real instructions are in the request body payload rather than different endpoints HTTP methods query parameters and path parameters the main components of the service Now graphql API are the schema the resolvers and resolver mappings we'll go into more detail on each of these in the upcoming videos like other protocols the transaction is initiated from the client or consumer side in the case of graphql this is done via a query I'm using that term generically here to indicate any type of request when in fact there are two types of requests named query used to retrieve the data and mutation used to modified data on the target system let's do a quick comparison for those of you who are familiar with rest apis where rest apis typically have multiple endpoints or URLs to access information in different ways graphql simplifies this with a single endpoint often for a group of similar operations like case management inventory or return Goods authorization rest apis use different HTTP methods like get for retrieving information post for creating a new record or put in patch to update and of course delete graphql uses two types of request query to retrieve and mutation to modify and because the request is always sent as part of the HTTP body a post method is always used further simplifying the construction of new Integrations another big difference is the way the response is sent from the provider in most rest apis you get whatever the provider sends despite how much of that information is actually useful to you at the time let's say for example you want to know the service now stock price with rest you would send a ticker symbol and make it back the current price today's high and low the 52e range market cap PE ratio earnings per share and more when all you really wanted was the current price with graphql the client or consumer specifies what is desired if all you want is the current stock price that's all you get back I know this is a fairly simple and small example but you get the idea where speed and cost are impacted when you scale this up and here's another thing to note about graphql the server or provider specifies what's available in the form of a schema this gives the author control over what's being offered consider the example of the service now table rest API you may use the cisp parum under Fields query parameter to let your third party know of some of the fields available but if they're Savvy and have proper ACLS they can extend that and read fields from the table that you may not intend with graphql you get better control over what's available if the author of The schema didn't include it you can't get it it's as if that field or property doesn't even exist as a quick example here's the basic components of a simple fql query the first thing to note is that it almost looks like Json with structured curly brackets except there's no field value pairs this is a query because it doesn't say mutation in the absence of the query word appearing first it's assumed to be a query request inside these first braces is the application namespace this is a camel case version of the appscope name X under snc under mm in this case next we have hello world the schema name space this is derived from the API name in much the same way that script includes use the name to create an API name inside the schema namespace we have one or more query names I like to think of these as functions that the API can perform in this case we'd like to run the get Hello World function often these are named so you can easily tell what it is like update customer increment discount or get all clients finally we get to the properties we want in this case we want the message property from the schema from this example we don't know what else it has to offer there could be more but all we want right now by looking at this query is that the query request to the value of message we'll get more into the details of a query and building out more complex examples in the next few videos one more thing new lines and tabs are optional you'll often see these when building an API but they're completely optional personally I find the queries especially longer more complex ones easier to read in this prettified format but some providers May stipulate that new lines and tabs are to be removed later in this series I'll show you a way to create and maintain readable queries that can be trimmed down if the producer needs that that's a quick overview now let's get set up to do some building and testing in the next video
https://www.youtube.com/watch?v=sP_CelE8GGI