Created
October 6, 2021 23:42
-
-
Save LuigiClaudio/59ed074380b5cdabe9ebfac54be0c9f3 to your computer and use it in GitHub Desktop.
graphql Apollo server - resolver - connect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createBrand: async ( | |
_, | |
{ | |
data: { | |
name, | |
brandWatchList: { connect: id }, | |
}, | |
}, | |
{ user }, | |
) => { | |
const client = new faunadb.Client({ secret: process.env.FAUNA }); | |
if (!user) { | |
throw new Error('Must be authenticated to create a brand'); | |
} | |
const results = await client.query( | |
q.Create(q.Collection('Brand'), { | |
data: { | |
name, | |
brandWatchList: q.Ref(q.Collection('BrandWatchList'), id), | |
owner: user, | |
}, | |
}), | |
); | |
return { | |
...results.data, | |
_id: results.ref.id, | |
}; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment