How to decide what root value to use for GraphQL mutations -


i'm experimenting graphql , need understanding how know root value provide when mutation performed.

concrete example: want update username of logged in user. mutation looks this:

 mutation testmutation {        updatemyusername(newname: "coolname") {                        username } } 

the root object provide here current user. how know when receive mutation without parsing , seeing name? no decision possible based on url 1 endpoint exists. , parsing string send further parsed again sounds wasteful @ best.

is maybe common practice instead provide parameters in url or request body give application more context?

it's not common include more data in url, since each mutation backed function, not need parse name, can define in function.

since mutations top level, root object top level root object. if need access different object, need ensure you've provided enough information retrieve it

to keep track of logged in user, check out context, 1 of initial arguments run graphql query , provided in each resolution function. context used keep track of logged in user.

now have both function defines "changemyusername", have logged in user, , have provided arguments new username, should have need implement body of function.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -