How do I get relations in GraphQL?2019 Community Moderator ElectionReturn data to GraphQL from Promisegraphql server email verify exampleHow to combine few mutations in the ifelse logic in order to get 'GetOrCreateUser'?how to return token from graphql mutationCompiler error with PrismaResponding with a custom HTTP code with GraphQL Yoga from a mutation resolverGraphQL data modelling - extended types (Prisma)Graphql mutation sequelize not returning dataLogin Mutation for Graphql not finding userGraphQL and mongoose return nulll while authenticating user

How to find the largest number(s) in a list of elements?

How do researchers send unsolicited emails asking for feedback on their works?

Weird lines in Microsoft Word

Extraneous elements in "Europe countries" list

Isn't the word "experience" wrongly used in this context?

TDE Master Key Rotation

UK Tourist Visa- Enquiry

Unfrosted light bulb

Do native speakers use "ultima" and "proxima" frequently in spoken English?

Are hand made posters acceptable in Academia?

Is xar preinstalled on macOS?

What will the Frenchman say?

Does convergence of polynomials imply that of its coefficients?

Turning a hard to access nut?

Should I be concerned about student access to a test bank?

Would it be believable to defy demographics in a story?

Single word to change groups

Air travel with refrigerated insulin

Hackerrank All Women's Codesprint 2019: Name the Product

How are passwords stolen from companies if they only store hashes?

Help with identifying unique aircraft over NE Pennsylvania

Why is "la Gestapo" feminine?

Friend wants my recommendation but I don't want to

Difficulty understanding group delay concept



How do I get relations in GraphQL?



2019 Community Moderator ElectionReturn data to GraphQL from Promisegraphql server email verify exampleHow to combine few mutations in the ifelse logic in order to get 'GetOrCreateUser'?how to return token from graphql mutationCompiler error with PrismaResponding with a custom HTTP code with GraphQL Yoga from a mutation resolverGraphQL data modelling - extended types (Prisma)Graphql mutation sequelize not returning dataLogin Mutation for Graphql not finding userGraphQL and mongoose return nulll while authenticating user










1















I have the following data model in prisma.



type User 
id: ID! @unique
name: String!
email: String! @unique
password: String!
...etc
userTypeA: UserTypeA @relation(name: "UserOnUserTypeA")
userTypeB: UserTypeB @relation(name: "UserOnUserTypeB")


type UserTypeA
id: ID! @unique
user: User @relation(name: "UserOnUserTypeA")
userTypeB: [userTypeB!]!


type UserTypeB
id: ID! @unique
user: User @relation(name: "UserOnUserTypeB")
userTypeA: UserTypeA!
...etc



I also have 2 resolvers, one for registration which returns only UserTypeA and one for login which returns any kind of user.



async register(parent, args, ctx, info) 
args.email = args.email.toLowerCase();
const password = await bcrypt.hash(args.password, 10);
const user = await ctx.db.mutation.createUser(

data:
...args,
password

,
info
);
const userTypeA = await ctx.db.mutation.createUserTypeA(

data:
user:
connect:
id: user.id



,
info
);
const token = jwt.sign( userId: userTypeA.id , process.env.APP_SECRET);
ctx.response.cookie("token", token,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 365
);
return userTypeA;
,

async login(parent, email, password , ctx, info)
const user = await ctx.db.query.user( where: email: email );
if (!user)
throw new Error("No user found");

const valid = await bcrypt.compare(password, user.password);
if (!valid)
throw new Error("Invalid Password!");

const token = jwt.sign( userId: user.id , process.env.APP_SECRET);
ctx.response.cookie("token", token,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 365
);
return user;
,


The register mutation correctly returns a UserTypeA and nested I can find information from the User model. However when I use the login mutation I get information about the user but the nested UserTypeA comes as null.



In a tutorial by Wes Bos Advanced React where he makes a Full-Stack Application with React and GraphQL/Prisma (an online shop) he uses the same resolvers and gets the nested information about the user (like cart items) which are defined in the model as relations.



PS. Keep in mind that I'm a GraphQL/Prisma newbie. Thanks!










share|improve this question
























  • I think you have to write query resolvers for UserTypeA and UserTypeB

    – Soulimane Mammar
    Mar 7 at 23:58















1















I have the following data model in prisma.



type User 
id: ID! @unique
name: String!
email: String! @unique
password: String!
...etc
userTypeA: UserTypeA @relation(name: "UserOnUserTypeA")
userTypeB: UserTypeB @relation(name: "UserOnUserTypeB")


type UserTypeA
id: ID! @unique
user: User @relation(name: "UserOnUserTypeA")
userTypeB: [userTypeB!]!


type UserTypeB
id: ID! @unique
user: User @relation(name: "UserOnUserTypeB")
userTypeA: UserTypeA!
...etc



I also have 2 resolvers, one for registration which returns only UserTypeA and one for login which returns any kind of user.



async register(parent, args, ctx, info) 
args.email = args.email.toLowerCase();
const password = await bcrypt.hash(args.password, 10);
const user = await ctx.db.mutation.createUser(

data:
...args,
password

,
info
);
const userTypeA = await ctx.db.mutation.createUserTypeA(

data:
user:
connect:
id: user.id



,
info
);
const token = jwt.sign( userId: userTypeA.id , process.env.APP_SECRET);
ctx.response.cookie("token", token,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 365
);
return userTypeA;
,

async login(parent, email, password , ctx, info)
const user = await ctx.db.query.user( where: email: email );
if (!user)
throw new Error("No user found");

const valid = await bcrypt.compare(password, user.password);
if (!valid)
throw new Error("Invalid Password!");

const token = jwt.sign( userId: user.id , process.env.APP_SECRET);
ctx.response.cookie("token", token,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 365
);
return user;
,


The register mutation correctly returns a UserTypeA and nested I can find information from the User model. However when I use the login mutation I get information about the user but the nested UserTypeA comes as null.



In a tutorial by Wes Bos Advanced React where he makes a Full-Stack Application with React and GraphQL/Prisma (an online shop) he uses the same resolvers and gets the nested information about the user (like cart items) which are defined in the model as relations.



PS. Keep in mind that I'm a GraphQL/Prisma newbie. Thanks!










share|improve this question
























  • I think you have to write query resolvers for UserTypeA and UserTypeB

    – Soulimane Mammar
    Mar 7 at 23:58













1












1








1








I have the following data model in prisma.



type User 
id: ID! @unique
name: String!
email: String! @unique
password: String!
...etc
userTypeA: UserTypeA @relation(name: "UserOnUserTypeA")
userTypeB: UserTypeB @relation(name: "UserOnUserTypeB")


type UserTypeA
id: ID! @unique
user: User @relation(name: "UserOnUserTypeA")
userTypeB: [userTypeB!]!


type UserTypeB
id: ID! @unique
user: User @relation(name: "UserOnUserTypeB")
userTypeA: UserTypeA!
...etc



I also have 2 resolvers, one for registration which returns only UserTypeA and one for login which returns any kind of user.



async register(parent, args, ctx, info) 
args.email = args.email.toLowerCase();
const password = await bcrypt.hash(args.password, 10);
const user = await ctx.db.mutation.createUser(

data:
...args,
password

,
info
);
const userTypeA = await ctx.db.mutation.createUserTypeA(

data:
user:
connect:
id: user.id



,
info
);
const token = jwt.sign( userId: userTypeA.id , process.env.APP_SECRET);
ctx.response.cookie("token", token,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 365
);
return userTypeA;
,

async login(parent, email, password , ctx, info)
const user = await ctx.db.query.user( where: email: email );
if (!user)
throw new Error("No user found");

const valid = await bcrypt.compare(password, user.password);
if (!valid)
throw new Error("Invalid Password!");

const token = jwt.sign( userId: user.id , process.env.APP_SECRET);
ctx.response.cookie("token", token,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 365
);
return user;
,


The register mutation correctly returns a UserTypeA and nested I can find information from the User model. However when I use the login mutation I get information about the user but the nested UserTypeA comes as null.



In a tutorial by Wes Bos Advanced React where he makes a Full-Stack Application with React and GraphQL/Prisma (an online shop) he uses the same resolvers and gets the nested information about the user (like cart items) which are defined in the model as relations.



PS. Keep in mind that I'm a GraphQL/Prisma newbie. Thanks!










share|improve this question
















I have the following data model in prisma.



type User 
id: ID! @unique
name: String!
email: String! @unique
password: String!
...etc
userTypeA: UserTypeA @relation(name: "UserOnUserTypeA")
userTypeB: UserTypeB @relation(name: "UserOnUserTypeB")


type UserTypeA
id: ID! @unique
user: User @relation(name: "UserOnUserTypeA")
userTypeB: [userTypeB!]!


type UserTypeB
id: ID! @unique
user: User @relation(name: "UserOnUserTypeB")
userTypeA: UserTypeA!
...etc



I also have 2 resolvers, one for registration which returns only UserTypeA and one for login which returns any kind of user.



async register(parent, args, ctx, info) 
args.email = args.email.toLowerCase();
const password = await bcrypt.hash(args.password, 10);
const user = await ctx.db.mutation.createUser(

data:
...args,
password

,
info
);
const userTypeA = await ctx.db.mutation.createUserTypeA(

data:
user:
connect:
id: user.id



,
info
);
const token = jwt.sign( userId: userTypeA.id , process.env.APP_SECRET);
ctx.response.cookie("token", token,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 365
);
return userTypeA;
,

async login(parent, email, password , ctx, info)
const user = await ctx.db.query.user( where: email: email );
if (!user)
throw new Error("No user found");

const valid = await bcrypt.compare(password, user.password);
if (!valid)
throw new Error("Invalid Password!");

const token = jwt.sign( userId: user.id , process.env.APP_SECRET);
ctx.response.cookie("token", token,
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 365
);
return user;
,


The register mutation correctly returns a UserTypeA and nested I can find information from the User model. However when I use the login mutation I get information about the user but the nested UserTypeA comes as null.



In a tutorial by Wes Bos Advanced React where he makes a Full-Stack Application with React and GraphQL/Prisma (an online shop) he uses the same resolvers and gets the nested information about the user (like cart items) which are defined in the model as relations.



PS. Keep in mind that I'm a GraphQL/Prisma newbie. Thanks!







graphql prisma






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 23:36







George Kostopoulos

















asked Mar 7 at 18:34









George KostopoulosGeorge Kostopoulos

2515




2515












  • I think you have to write query resolvers for UserTypeA and UserTypeB

    – Soulimane Mammar
    Mar 7 at 23:58

















  • I think you have to write query resolvers for UserTypeA and UserTypeB

    – Soulimane Mammar
    Mar 7 at 23:58
















I think you have to write query resolvers for UserTypeA and UserTypeB

– Soulimane Mammar
Mar 7 at 23:58





I think you have to write query resolvers for UserTypeA and UserTypeB

– Soulimane Mammar
Mar 7 at 23:58












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050623%2fhow-do-i-get-relations-in-graphql%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050623%2fhow-do-i-get-relations-in-graphql%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page