philch
05/20/2018, 3:58 PMctx.db.exists.Type
always returns true no matter what args? Am I misunderstanding how it is supposed to work?
await <http://ctx.db.exists.Post|ctx.db.exists.Post>({
title: 'blah',
})
should return false but instead it looks like it is just querying the server for all posts and returning true.medelman
05/20/2018, 4:42 PMphilch
05/20/2018, 4:57 PMendpoint: ${env:PRISMA_ENDPOINT}
secret: ${env:PRISMA_SECRET}
# the file path pointing to your data model
datamodel: datamodel.graphql
# seed your service with initial data based on seed.graphql
seed:
import: seed.graphql
hooks:
post-deploy:
- echo "Deployment finished"
- graphql get-schema --project database
- graphql codegen
philch
05/20/2018, 4:58 PMprojects:
app:
schemaPath: "src/schema.graphql"
extensions:
endpoints:
default: "<http://localhost:4000>"
database:
schemaPath: "src/generated/prisma.graphql"
extensions:
prisma: database/prisma.yml
codegen:
- generator: prisma-binding
language: typescript
output:
binding: src/generated/prisma.ts
philch
05/20/2018, 5:00 PMasync deletePost(parent, { id }, ctx: Context, info) {
const { userId } = ctxUser(ctx);
const postExists = await <http://ctx.db.exists.Post|ctx.db.exists.Post>({
id,
author: { id: userId },
});
if (!postExists) {
throw new Error(`Post not found or you're not the author`);
}
return ctx.db.mutation.deletePost({ where: { id } });
},
};
philch
05/20/2018, 5:00 PMmedelman
05/20/2018, 5:18 PMphilch
05/20/2018, 5:20 PMquery:
{
posts {
id
}
}
philch
05/20/2018, 5:20 PMmedelman
05/20/2018, 5:20 PMmedelman
05/20/2018, 5:20 PMmedelman
05/20/2018, 5:22 PMprivate buildExists(): Exists {
const queryType = this.schema.getQueryType()
if (!queryType) {
return {}
}
if (queryType) {
const types = getTypesAndWhere(queryType)
return types.reduce((acc, { type, pluralFieldName }) => {
return {
...acc,
[type]: args =>
this.delegate(
'query',
pluralFieldName,
{ where: args },
buildExistsInfo(pluralFieldName, this.schema),
).then(res => res.length > 0),
}
}, {})
}
return {}
}
philch
05/20/2018, 5:23 PM<http://ctx.db.exists.Post|ctx.db.exists.Post>({ title: 'fake' })
is still just runs the id querymedelman
05/20/2018, 5:25 PMphilch
05/20/2018, 5:26 PMRequest to <http://localhost:4466/backend/dev>:
query:
{
posts {
id
}
}
operationName: null
variables:
{}
Response from <http://localhost:4466/backend/dev>:
{
"posts": [
{
"id": "cjhf0v2x5000i09817s7dhdhz"
},
{
"id": "cjhf0v2x5000j0981dsjdvnns"
}
]
}
philch
05/20/2018, 5:28 PMphilch
05/20/2018, 5:29 PMmedelman
05/20/2018, 5:29 PMphilch
05/20/2018, 5:30 PMmedelman
05/20/2018, 5:30 PMmedelman
05/20/2018, 5:31 PMlet id, ownerId
const mediaExists = await ctx.db.exists.Media({ id, owner: {id: ownerId} })
returns true for me.philch
05/20/2018, 5:31 PMmedelman
05/20/2018, 5:31 PMphilch
05/20/2018, 5:31 PM<http://ctx.db.exists.Post|ctx.db.exists.Post>({ title: 'fake' })
philch
05/20/2018, 5:32 PMmedelman
05/20/2018, 5:32 PMphilch
05/20/2018, 5:34 PMphilch
05/20/2018, 5:34 PMcodegen:
- generator: prisma-binding
language: typescript
output:
binding: src/generated/prisma.ts
philch
05/20/2018, 5:35 PMmedelman
05/20/2018, 5:43 PMphilch
05/20/2018, 5:50 PMphilch
05/20/2018, 5:51 PMmedelman
05/20/2018, 5:52 PMphilch
05/20/2018, 5:52 PMphilch
05/20/2018, 10:17 PMphilch
05/20/2018, 10:17 PMmedelman
05/20/2018, 10:18 PMmedelman
05/20/2018, 10:18 PMphilch
05/20/2018, 10:21 PMmedelman
05/24/2018, 4:34 PM