GraphQL Tutorial #9 - The Resolve Function

preview_player
Показать описание
Hey all, in this GraphQL tutorial I'll show you how we can use the resolve function to go out and actually grab our data for the GraphQL server to return to the front-end.

----- COURSE LINKS:

======== Other Tutorials =========

----- NODE.JS TUTORIALS

----- MONGODB TUTORIALS

----- REACT TUTORIALS

======== Social Links ==========

Рекомендации по теме
Комментарии
Автор

//Dummy data for lazy ones :)

const books = [
{name: 'Name of the Wind', genre: 'Fantasy', id: '1'},
{name: 'The Final Empire', genre: 'Fantasy', id: '2'},
{name: 'The Long Earth', genre: 'Sci-Fi', id: '3'}
]

Ladyhoat
Автор

You can use es6 instead of lodash like so: return book.find(book => book.id == args.id)

haciendadad
Автор

Very cool, but why not encourage using ES6 Find instead of downloading lodash and installing it just to do the same thing?

incarnateTheGreat
Автор

Thank you for these tutorials, they're just the right amount of info!

jesseallaway
Автор

Finally ! A course that has enabled me to successfully set up a Graphql server - Thanks !!

garybarnes
Автор

hey, bro, I'm from Morocco & I'm so glad to watching ur videos are very helpful ; I have one question about resolve function : what's the needed of parent & why u passed in resolve function ?? thank u :)

moulcode
Автор

For those looking for :
// dummy data
var books = [
{ name: 'Name of the Wind', genre: 'Fantasy', id: '1' },
{ name: 'The Final Empire', genre: 'Fantasy', id: '2' },
{ name: 'The Long Earth', genre: 'Sci-Fi', id: '3' },
];

mukeshjaiswal
Автор

We're good to use the filter method to return the book right?

MobiusCoin
Автор

Why did we use lodash instead of `return books.find(book => book.id === args.id); `

baibhavgautam
Автор

It's a beauty! Je bois vos paroles ;)

gglandshomeunixorg
Автор

If you have got errors like graphqlTTP is not function, try destructure it from express-graphql

alexgeorge
Автор

Hey Mr. Ninja! One beginner question for ya. I am wondering why I can't use javascript filter loop instead of lodash :)

Ladyhoat
Автор

I am getting this error Could not find name 'book'. Did you mean 'books'?ts(2570). Surprised nobody is getting this error. Also GitHub Does not even have the below code.
book(id:"2"){
name
genre
}

I have very little understanding for nodejs right now, I have worked in JavaScript way before these things arrived.

DineshChaturvedi-tp
Автор

Why use lodash?

books.find(({ id: bookID}) => bookID === id)

nathanie
Автор

"loadash" is no longer supported and has been deprecated,
instead use "npm i lodash"

knowledgeforsuccess
Автор

resolve(parent, args) {
// code to get data from db / other source
// return _.find(books, { id: args.id });
// without lodash
return books.find(book => book.id === args.id);
}

stanleylouis
Автор

Why require the ID, a randomly generated string, to look up a db item?? Nobody explains that. I would rather look up by title or author or some other human-friendly parameter!

terrybabb
Автор

I followed all the steps as you told in this series, but the localhost is not responding, I think I made mistake is schema, can you please help me the code is in github repository

harshalrajput
Автор

Hi, I'm facing a problem - the query in graphiql gives an error: "return_ is not defined" - I can't find the reason - googled several times but find nothing // this series is awesome, thanks

databasenomad
Автор

You are just adding packages like nothing. It just complicates everything instead of understanding.

yashuagrawal
welcome to shbcf.ru