This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Use GraphQL Primitive Types

1:57 JavaScript lesson by

GraphQL’s Type System has support for a number of Primitive Types that we can use in our GraphQL Schema definitions. In this video, we’ll take a look at String, Boolean, Int, Float, and ID and how to incorporate them into a GraphQL Schema Definition.


egghead.io comment guidelines

Avatar
egghead.io

GraphQL’s Type System has support for a number of Primitive Types that we can use in our GraphQL Schema definitions. In this video, we’ll take a look at String, Boolean, Int, Float, and ID and how to incorporate them into a GraphQL Schema Definition.

Let's start out by opening up our index.js file in our text editor of choice, and take a look at the GraphQL schema that we've created here. In this schema, we've actually defined a query type, and it exposes a single field called "foo," that's of type string.

In this case, string is a GraphQL primitive types, and we actually have several primitive types available to us when we try and define fields on our schema. Let's go ahead and try and add some more primitive types now to this query type.

To start off, let's make a field called "ID" that's of type ID. We'll update foo here to be a title, and title is a string. We could also have a field called "duration," which has a type of int, we could also have a field called "watched," which is of type Boolean.

Now, if wanted to make sure that our schema could resolve each of these types, we would go to our resolvers, we'd create one for ID, and in this case, we could have the ID of 1. We'd update the foo field to title, we would change duration to some kind of integer, and then watched would be a Boolean value.

Now with all these resolvers defined, we can go and update our query to request the field ID, the fields title, the field duration, and finally, the field watched, and we can use the GraphQL call to execute our given query against the schema.

Let's go ahead and run that in our terminal, I'll do node index.js, and now, we go ahead and get our response containing a datafield. Inside of the datafield we have the ID, the title, the duration, and the watched values being returned to us.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?