⚠️ This lesson is retired and might contain outdated information.

Use GraphQL Primitive Types

Josh Black
InstructorJosh Black
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated 2 years ago

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.

[00:00] 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.

[00:19] 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.

[00:36] 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.

[00:58] 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.

[01:22] 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.

[01:39] 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.

egghead
egghead
~ 2 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today