Timo
11/26/2020, 1:33 PMdeclarativeWrappingPlugin
warnings is quite a lot. Now, I could simply use the plugin, but what if that code gets deprecated in the near future?
Again, really appreciate the work you're doing! I'm simply missing a bit more communication on what we can expect from changes related to schema, because I'm not really too keen on rewriting my code over and over again.Peter
11/26/2020, 7:00 PMexport type input = keyof QueryGetBtsArgs;
const getBts = async (_, arg) => {
const variables = {
...arg,
};
const data = await client(
endpoint,
gql`
query getBts($input: input) {
getBts(input: $input) {
province {
name
}
provider {
name
}
location {
name
}
}
}
`,
variables,
);
return data;
};
and my type QueryGetBtsArgs looks like this:
export type QueryGetBtsArgs = {
minLat?: Maybe<Scalars['Float']>;
maxLat?: Maybe<Scalars['Float']>;
minLong?: Maybe<Scalars['Float']>;
maxLong?: Maybe<Scalars['Float']>;
providers?: Maybe<Array<Maybe<ProviderEnum>>>;
technologies?: Maybe<Array<Maybe<TechnologyEnum>>>;
frequencies?: Maybe<Array<Maybe<FrequencyEnum>>>;
province?: Maybe<ProvinceEnum>;
location?: Maybe<Scalars['String']>;
skip?: Maybe<Scalars['Int']>;
};
I have error
Error: Unknown type "input". Did you mean "Int"?: {"response":{"errors":[{"message":"Unknown type \"input\". Did you mean \"Int\"?","locations":[{"line":2,"column":28}],"
how I should extend this args from QueryGetBtsArgs and pass it to query?
Thanks for help 😉Elvijs
11/27/2020, 10:03 PMJustin Voitel
11/28/2020, 5:32 PMKevin Rejko
12/01/2020, 8:01 PMJonathan
12/02/2020, 12:46 PMt.field
. I sometimes have a parent fetching basically all properties for all the nested resolvers, but I dont wish to specify an explicit resolver bellow. If I were to do something like
t.field('nestedField', { type: NestedFieldType, resolve: (parent => parent.nestedFieldType)})
, typescript complains that parent has no property nestedFIeldPeter
12/02/2020, 2:41 PMnonNullDefaults: {
output: true,
}
to my existing objectType and have error on resolvers in this type
Type '(root: Bts, args: any, ctx: { prisma: PrismaClient<PrismaClientOptions, never>; }) => Prisma__StationIdClient<StationId | null>' is not assignable to type 'FieldResolver<"Bts", "stationId">'.
Type 'Prisma__StationIdClient<StationId | null>' is not assignable to type 'StationId | PromiseLike<StationId> | { id: MaybePromise<number>; name: MaybePromise<string>; } | PromiseLike<StationId | { ...; }>'.
Type 'Prisma__StationIdClient<StationId | null>' is not assignable to type 'PromiseLike<StationId | { id: MaybePromise<number>; name: MaybePromise<string>; }>'.
Types of property 'then' are incompatible.
Type '<TResult1 = StationId | null, TResult2 = never>(onfulfilled?: ((value: StationId | null) => TResult1 | Promise<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | Promise<...>) | ... 1 more ... | undefined) => Promise<...>' is not assignable to type '<TResult1 = StationId | { id: MaybePromise<number>; name: MaybePromise<string>; }, TResult2 = never>(onfulfilled?: ((value: StationId | { id: MaybePromise<number>; name: MaybePromise<...>; }) => TResult1 | PromiseLike<...>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | ... 1 more ...'.
Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
Types of parameters 'value' and 'value' are incompatible.
Type 'StationId | null' is not assignable to type 'StationId | { id: MaybePromise<number>; name: MaybePromise<string>; }'.
Type 'null' is not assignable to type 'StationId | { id: MaybePromise<number>; name: MaybePromise<string>; }'.
67 resolve(root, args, ctx) {
~~~~~~~
Object look like this
export const Bts = objectType({
name: 'Bts',
description: 'BTS details',
nonNullDefaults: {
output: true,
},
definition(t) {
t.id('id')
t.string('lac'),
t.string('btsid'),
t.string('cid1'),
t.string('ECID'),
t.float('latitude'),
t.float('longitude'),
t.field('provider', {
type: 'Provider',
resolve(root, args, ctx) {
return ctx.prisma.provider.findOne({
where: { id: root.providerId },
})
},
}),
t.field('province', {
type: 'Province',
resolve(root, args, ctx) {
return ctx.prisma.province.findOne({
where: { id: root.provinceId },
})
},
}),
t.field('place', {
type: 'Place',
resolve(root, args, ctx) {
return ctx.prisma.place.findOne({
where: { id: root.placeId },
})
},
}),
t.field('location', {
type: 'Location',
resolve(root, args, ctx) {
return ctx.prisma.location.findOne({
where: { id: root.locationId },
})
},
}),
t.field('technology', {
type: 'Technology',
resolve(root, args, ctx) {
return ctx.prisma.technology.findOne({
where: { id: root.technologyId },
})
},
}),
t.field('frequency', {
type: 'Frequency',
resolve(root, args, ctx) {
return ctx.prisma.frequency.findOne({
where: { id: root.frequencyId },
})
},
}),
t.field('stationId', {
type: 'StationId',
resolve(root, args, ctx) {
return ctx.prisma.stationId.findOne({
where: { id: root.stationIdId },
})
},
})
},
})
and other type that is included here also have nonNullDefaults flagSwapnull
12/02/2020, 4:35 PMconst isAuthed = rule()(async (parent, args, ctx) => {
const recordId = ctx.where?.id?.equals;
/* do rest of auth using recordId */
}
This obviously sucks because if the FE chooses to use in
or contains
or any other input, it won't work.
One thing we have thought is to allow something like
query getRecords {
records(recordId: "someId") {
uuid
}
}
But when creating the record query we have
t.crud.records({ filtering: true, ordering: true, pagination: true });
and we can't find a way to say for type query
on records
accept a recordId
argument.
The other option is to run the query and then check when it comes back.
Anybody have any thoughts on how they are authorising these types of owned records?Stefan N
12/03/2020, 7:51 AMnode_modules/@types/typegen-nexus-plugin-prisma/
automatically when running the server in dev mode. But I need it to generate these types as a build step in CI/CD (otherwise next build fails as well). I do manage to generate the schema.graphql
and nexus.ts
running reflection like this npx ts-node -T ./graphql/schema/index.ts
and using the flag shouldExitAfterGenerateArtifacts
. But during this step, the nexus-plugin-prisma files do not seem to be generated. Here my code generating the schema: https://github.com/teachen-ch/voty/blob/d525c36a0a7cff85816804e86f3b854cac480d69/graphql/makeschema.ts#L12Stefan N
12/03/2020, 7:54 AMShreyas Sreenivas
12/03/2020, 9:22 AMjest
. Is there a reason why in the Nexus Documentation they’re using Snapshot testing instead of just using expect(result).toEqual(exampleResult)
? Is it just for convenience or is there something that I’m missing?Stefan N
12/03/2020, 12:57 PMSytten
12/03/2020, 7:37 PMPaul Hendrickson
12/03/2020, 9:30 PMsven
12/04/2020, 10:07 AMPaul Hendrickson
12/04/2020, 4:25 PMcustomers(
where: { firstName: startsWith: “Paul”, mode: insensitive }},
first: 20
orderBy: [{ lastName : asc }, { id : asc } ]
){
firstName
lastName
count
id
}
so you can see how many Pauls there are but only return the first 20sylflo
12/04/2020, 7:19 PMoriginalResolve
, I am not even quite sure if it is useful.
but is doing this, the correct way ?
const customer: NexusGenObjects["Customer"] | null = await originalResolve(root, args, ctx, info);
but once again, it's maybe quite useless to do soAwey
12/06/2020, 12:51 AMidArg()
or stringArg()
be used with the uuid()
that comes from prisma?Stefan Trivuncic
12/06/2020, 10:28 PMUsers
model, I have a model called LocationStatus
with the enum values set as:
import { enumType } from '@nexus/schema'
export const LocationStatus = enumType({
name: 'LocationStatus',
members: ['ON', 'OFF', 'APP'],
description: 'List of location status'
})
But I need to pass it as an argument here:
t.field('setLocationStatus', {
type: 'User',
args: {
locationStatus: arg({ type: 'LocationStatus', list: true})
},
resolve: async (_parent, { locationStatus }, ctx ) => {
const userId = await getUserId(ctx)
if (!userId) {
throw new Error('Invalid userId')
}
return await ctx.prisma.user.update({
where: {
id: userId
},
data: { locationStatus }
})
}
})
And the error I get is due to the conflicting input types: Type 'string | null | undefined' is not assignable to type '"ON" | "OFF" | "APP" | EnumLocationStatusFieldUpdateOperationsInput | undefined'.
Awey
12/07/2020, 8:05 PMenum PostType {
story
ask
show
}
Would you write it like so in NexusSchema?
const PostType = enumType({
name: 'PostType',
members: ['story', 'ask', 'show'],
})
How then would I go about using this PostType enum as an argument?
args: {
title: nonNull(stringArg()),
type: nonNull(PostType),
url: stringArg(),
content: stringArg(),
},
Awey
12/08/2020, 11:43 PMSlackbot
12/09/2020, 8:32 PMAdam
12/10/2020, 12:59 AMauthroization
resolvers correctly. So if I have two related tables, and need to implement a custom resolver
for retrieving Projects
based on permissions, then I have to put it on both entities? I thought if I typed a field as a related object
then it would use that object's resolver?
It seems like identical logic could get duplicated in quite a few places to cover all the related entities that might request a related objectType
model Organization {
id Int @id @default(autoincrement())
projects Project[]
}
model Project {
id Int @id @default(autoincrement())
organization Organization @relation(fields: [organizationId], references: [id])
organizationId Int
}
And then I define the types for each
export const OrganizationType = objectType({
name: 'Organization',
definition(t) {
const { model } = t;
model.id();
model.projects({
async resolve(_root, { where }, ctx, info, originalResolve) {
/** I Also need to put the logic here? If it knows I'm querying a Project, why doesn't it use the same logic? **/
}
});
},
});
export const ProjectType = objectType({
name: 'Project',
definition(t) {
const { model } = t;
model.id();
model.organizationId({});
model.organization({});
},
});
export const ProjectQueries = extendType({
type: 'Query',
definition(t) {
const { crud } = t;
crud.project({
filtering: true,
async resolve(_root, { where }, ctx, info, originalResolve) {
/** Filter only the projects that the user can see **/
}
});
Dickson
12/10/2020, 5:12 AMwrite EPIPE
error every now and then
{
"errors": [
{
"message": "write EPIPE",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"users"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"code": "EPIPE",
"clientVersion": "2.12.1"
}
}
}
],
"data": null,
"extensions": {
"tracing": {
"version": 1,
"startTime": "2020-12-10T04:52:35.819Z",
"endTime": "2020-12-10T04:52:35.827Z",
"duration": 8377223,
"execution": {
"resolvers": [
{
"path": [
"users"
],
"parentType": "Query",
"fieldName": "users",
"returnType": "[User!]!",
"startOffset": 344494,
"duration": 6622886
}
]
}
}
}
}
What could have gone wrong?Daniell
12/10/2020, 8:34 AMDaniell
12/12/2020, 8:37 AMSytten
12/13/2020, 4:07 PMAlex Vilchis
12/14/2020, 6:26 PMAlbert Gao
12/15/2020, 3:13 AMRicardo Almeida
12/15/2020, 8:46 AM