Stay on Topic 1

Lauro Silva
InstructorLauro Silva
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

To help make you become more comfortable with the idea of recording your very first lesson, we’ve compiled a few Lesson Feedback Cycles, taking an instructor from their first take to their final lesson, showing you where each instructor began with their lesson, and how they took in feedback from their coaches to create that final product we are proud to publish on egghead.io!

Take away from this feedback cycle: Stay on Topic 1

Instructor: [0:01] The first thing we need to do is to create a new project using yarn. This adds a package.json file to our project. Then we can install graphql-yoga on nodemon. Once the installation is complete, we can add the scripts that start the server with nodemon. Then we need to import { GraphQLServer } from 'graphql-yoga'.

[0:38] We can then create a server using the GraphQL server constructor we imported. It takes an object configuration, which can pass any type definitions and the resolvers. Then we can start the server using the start method. Also pass a port to the configuration object, let's say 4200, and then a callback function to be executed when the server starts running.

[1:21] Next you can go ahead to create a type definition. You can have a type computer just as an example with three fields. The first field is the model and it's required. The second is the maker, which is also required. The third one is the year it was made, which is also required and it's an integer.

[1:51] Then we need to create a query type to query this computer type. We want to get a list of computers. It returns an array called computerType.

[2:11] We can also create the resolvers, but for now let's leave it as an empty object so we can test our server so far. You can start the server by running yarn dev. Then let's reboot our browser.

[2:27] The browser opens up a playground where we can go ahead and inspect the schema we have. We can see computers query we have so far which returns a computerType.

[2:37] We can then add a query resolver which has just one field, the computers, and returns an array of computers, which you can name computersData. We can go ahead and create this computersData, which is an array of computers.

[3:05] Now we can save, and test if the query works in the playground. There you go, it sends back our computers array as the result of the query.

egghead
egghead
~ 6 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