logo

NJP

GraphQL Complex Data Types - Learn Integrations on the Now Platform

Import · Dec 04, 2023 · video

[Music] in this video we'll go beyond the basic primitive data types of strings integers booleans and so on to explore more complex data types to represent users companies departments assets or other objects in our graphql schema and how to interact with them from the client this video Builds on the demo from the previous one so if you haven't watch that one to see how to build a basic custom graphql API and how the components fit together strongly recommend you do so now the goal of this video is to help you understand how to create a complex data type use that data type as part of another schema type create the resolver and resolver mappings our case record has a couple fields that reference users we want to get those details so we'll need to create a new user type and reference it within the existing case type okay let's define a user type like this we'll only expose a few of the Glide record fields to the API in our schema using the at source directive to make it easy to retrieve the Glide record field values or display values like this notice that the user type also has a manager field of type user making the complex object self-referencing which is always nice now that the user type is defined let's add a couple more fields to our case type to identify the assigned to and customer Fields as user type like this and save our schema is updated so let's create a simple resolver script named get user to retrieve the user record from the CIS user table if you look closely at line six it does something interesting it uses both get arguments and get Source first it checks if an ID argument has been passed make making this resolver useful for retrieving a user by CIS ID if the schema supports it and the client requests it that way if an ID argument isn't available then it tries to get the CIS ID from get source which is how we'll be using it here this makes the single resolver script working two ways directly with the parameter and from at source directives and finally the all important resolver mappings so we'll come down to the related list and create a new graphql resolver mapping and notice that our path does not include an entry that starts with query colon because we don't have any unused entries in the query block of our schema what we do have are some fields that need the get user resolver to retrieve the user information so we'll choose case colon assigned to and connect it to get user and submit do the same for case colon customer and that self-referencing one in the user type user colon manager finally we'll go to the graphql Explorer and try a query like this to get the number short description State and impact plus we'll request the customer as an object from that we only want these three Fields we'll get the same three fields for assign to and run the query and there's our J un response with the embedded objects just like we requested now in this example customer and assigned to Fields were references within the case record but that doesn't have to be the case with custom objects these may be objects computed at runtime by the resolver that can be included into the schema and subsequent payload for this example we can see how to use complex data types to extend the power of graphql queries in the next video we'll take a look at making the queries more Dynamic and reusable using variables

View original source

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