Andrew O.
08/22/2019, 6:05 PMksm
08/22/2019, 8:17 PMPkmmte
08/23/2019, 12:08 AMget the top 10 users with the most posts
I get that I could create an index for this, but what if I want to apply a time filter for most posts created within a time period?Ghassen Ghabarou
08/23/2019, 12:26 AMAkshay Kadam (A2K)
08/23/2019, 9:43 AMdatamodel.prisma
to:
type Pokemon {
id: ID! @id @unique
number: Int! @unique
name: String!
attacks: PokemonAttack
}
type PokemonAttack {
id: Int! @id
special: [Attack]
}
type Attack {
id: Int! @id
name: String
damage: String
}
And changed Query.js
to:
import { prismaObjectType } from 'nexus-prisma';
export const Query = prismaObjectType({
name: 'Query',
definition(t) {
t.crud.findManyPokemon({
alias: 'pokemons'
})
t.list.field('pokemon', {
type: 'Pokemon',
args: {
name: stringArg(),
},
resolve: (parent, { name }, ctx) => {
return ctx.prisma.pokemon.findMany({
where: {
name
}
})
},
})
},
});
Then I deployed the whole thing but I still don't get name
as an argument on field pokemon
. Idk what I am doing wrong.
The complete code is in the subdirectory prisma1-demo
→ https://github.com/deadcoder0904/graphql-and-urql-by-example/tree/master/prisma1-demo
I've tried writing it from scratch and by downloading a boilerplate for the last 2 days but nothing seems to help. Any suggestions?Kashif
08/23/2019, 11:10 AMKashif
08/23/2019, 11:10 AMKashif
08/23/2019, 11:10 AMKashif
08/23/2019, 11:11 AMversion: '3'
services:
prisma:
image: prismagraphql/prisma:1.34
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
databases:
default:
connector: mysql
host: host.docker.internal
schema: prisma_prac
user: root
password: ''
rawAccess: true
port: '3306'
migrations: true
Kashif
08/23/2019, 11:24 AMversion: '3'
services:
prisma:
image: prismagraphql/prisma:1.34
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
databases:
default:
connector: mysql
host: host.docker.internal
schema: prisma_prac
user: root
password: ''
rawAccess: true
port: '3306'
migrations: true
Kennah
08/23/2019, 11:25 AMrdc
08/23/2019, 1:41 PMNgr Dev
08/23/2019, 1:46 PMprisma2
, nexus
and graphql-yoga
. I would like to query for multiple Posts for which I already know their id
.
Photon seems to support this with e.g. photon.posts.findMany({where: {OR: [{id: "post1"}, {id: "post2"}]}});
and by adding t.crud.findManyPost({alias: "posts"});
I can query for multiple posts, but the only arguments the graphQL query takes are the default ones (skip
to last
).
Is there a simple way to enable e.g. where
?
Thanks for your feedback!JBriggs
08/23/2019, 2:11 PM{ where: {or: { [ id: 1, id: 2 ] } } }
At least I canNgr Dev
08/23/2019, 2:37 PMwhere
. Or where should I put your snippet?
posts(
skip: Int
after: String
before: String
first: Int
last: Int
): [Post!]
JBriggs
08/23/2019, 2:38 PMcategories(where: CategoryWhereInput, orderBy: CategoryOrderByInput, skip: Int, after: String, before: String, first: Int, last: Int): [Category]!
JBriggs
08/23/2019, 2:38 PMJBriggs
08/23/2019, 2:38 PMJBriggs
08/23/2019, 2:38 PMJBriggs
08/23/2019, 2:39 PMNgr Dev
08/23/2019, 2:42 PMfirst
etc) with t.crud.findManyPost({alias: "posts", pagination: false});
, respectively pagination: true
.
Do I need to add some special property to enable where
?Novalis
08/23/2019, 3:27 PMOliver Evans
08/23/2019, 5:40 PMDaniel Mahon
08/24/2019, 12:51 AMDaniel Mahon
08/24/2019, 12:53 AMDaniel Mahon
08/24/2019, 12:54 AMRuslan Baigunussov
08/24/2019, 10:03 AMorderBy
option in my existing query? I already have some auto-generated option in this field, but how can I extend this?evondev
08/24/2019, 10:34 AMCorey Snyder
08/25/2019, 3:04 AMUser
on the Image Type
because I’ve no reason to query for the user based on the Image ID. But I don’t know how to make that call in the code to save.
type User {
id: ID! @id
name: String
images: [Image] @relation(onDelete: CASCADE)
}
type Image{
id: ID! @id
createdAt: DateTime! @createdAt
filename: String!
}
Normally my create calls look like this ⬇️ but I believe this code would require a user
field on my Image
type.
context.prisma.createImage({
filename: "test",
user: { connect: { id: args.user.id } }
})
Am I thinking about this correctly? Should you always have bi-directional references between the two tables with a relationship like this?Corey Snyder
08/25/2019, 3:20 AMtype Image{
id: ID! @id
createdAt: DateTime! @createdAt
product: Sandwich!
postedBy: User!
filename: String!
}
And as you can see it’s very tightly tied to Sandwiches 🥪. But what if I wanted to introduce a new Dessert
🍦 type which will also have images. How does one handle that? I don’t want to have to create a new DesertImages
Type as this won’t scale as I move into other products. And I can’t have the product
field point to both Sandwich
and Dessert
right?
This is going to be a problem I’ll run into, all over my code, real soon as I move on from having just 1 type of product in my app and I’m not sure how to handle it.