logo

NJP

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

Import · Dec 04, 2023 · video

[Music] in this video we'll cover resolvers the bits of serers side JavaScript code that perform the operations needed to make the schema come alive and return the appropriate response data we find resolvers in the graphql API record under the related list graphql scripted resolvers by default a new resolver has this process function with access to an EnV object we're free to add additional JavaScript code such as this example here we're using the env. getet arguments method to get access to the game ID parameter as defined by the schema and passed from the client that's then passed to a script include which does what it needs in the get game object function to return an appropriate object again defined by the schema while the resolver May return a large amount of data the client query defines which fields or properties it actually wants almost like a filter as in this example an array of question objects each with lots of properties are available however if the client only wants the question text that's all the API will return the resolver EnV object has another method called get source which is very handy for returning objects from the resolver and defining the actual field values in the schema let's take a look at this example the resolver at the top is set up to return one or more Glide record objects the schema has a type called user containing the fields ID active name and email we can see that the societ field is the mandatory ID type we then use the at source directive to indicate the value comes from the resolver Glide records field CIS .value now check out the active field it's a Boolean and the value of booleans on the platform is zero and one but the display value is used to provide a true or false in this case note that the display value here uses underscores resolvers are very powerful for getting exactly what you want from the database calculating values or constructing objects however they're no good unless they're mapped to the schema using one or more resolver mappings which is what we'll cover in the next video

View original source

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