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

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229