Skip to content

Instantly share code, notes, and snippets.

@LuigiClaudio
Created October 6, 2021 23:42
Show Gist options
  • Save LuigiClaudio/59ed074380b5cdabe9ebfac54be0c9f3 to your computer and use it in GitHub Desktop.
Save LuigiClaudio/59ed074380b5cdabe9ebfac54be0c9f3 to your computer and use it in GitHub Desktop.
graphql Apollo server - resolver - connect
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