rdunk
07/04/2020, 11:00 AMmikkelsl
07/06/2020, 8:14 AMDarryl
07/06/2020, 3:21 PM@nexus/schema
, I had quite a complicated mutation and for the input arg types, I was using what was auto-generated by nexus. Example code in the thread.Alex Vilchis
07/07/2020, 12:12 AMimport { GraphQLUpload } from 'graphql-upload';
import { schema } from 'nexus';
schema.scalarType({
...GraphQLUpload
});
export const Upload = GraphQLUpload;
...but I get an error in the console: BadRequestError: request.body json expected to have a query field
Lucas Munhoz
07/07/2020, 7:52 AMAndre Gustavo
07/08/2020, 8:24 PMimport { schema } from 'nexus'
import { getUserId } from '../utils'
schema.enumType({
name: 'RoleBookStatus',
members: ['BLOCKED', 'BORROWED', 'DAMAGED', 'ENABLED', 'UNENABLED'],
})
schema.objectType({
name: 'Book',
definition(t) {
t.model.id()
t.model.createdAt()
t.model.updatedAt()
t.model.title()
t.model.author()
t.model.publishedYear()
t.model.publishingCompany()
t.model.copies()
t.model.availability()
t.model.status()
t.model.categories()
t.model.createdBy()
},
})
schema.inputObjectType({
name: 'CreateBookInput',
definition(t) {
t.string('title', { required: true })
t.list.string('author', { required: true })
t.int('publishedYear', { required: true })
t.string('publishingCompany', { required: true })
t.int('copies', { required: true })
t.boolean('availability', { required: true })
t.field('status', { type: 'RoleBookStatus', required: true })
t.list.string('coverImage', { required: true })
},
})
schema.extendType({
type: 'Mutation',
definition(t) {
t.field('newBook', {
type: 'Book',
args: {
createBookInput: 'CreateBookInput',
categories: 'CategoryWhereUniqueInput',
},
resolve: async (_root, { createBookInput, categories }, ctx) => {
const userId = getUserId(ctx.token)
if (!userId) {
throw new Error('User identification failed!')
}
if (ctx.token && ctx.token.role === 'DEFAULT') {
throw new Error('Not Authorized user add this data!')
}
const createdBy = await ctx.db.user.findOne({ where: { id: userId } })
if (createdBy?.role === 'DEFAULT') {
throw new Error('Not Authorized user add this data!')
}
return await ctx.db.category.create({
data: {
...createBookInput,
categories,
createdBy: { connect: { id: userId } }
},
})
},
}),
},
// ------
})
Thank You!!!!!Andre Gustavo
07/08/2020, 8:24 PM{
"error": {
"errors": [
{
"message": "\nInvalid `prisma.category.create()` invocation in\n/home/castro/Cursos/Nexus/librarydash-nexus/api/graphql/Book.ts:86:46\n\n 82 data: {\n 83 ...createBookInput,\n 84 categories,\n 85 createdBy: { connect: { id: userId } },\n→ 86 // userId\n\n{\n data: {\n title: 'The book title sample',\n ~~~~~\n author: [\n ~~~~~~\n 'John Doe',\n 'Jane Doe'\n ],\n publishedYear: 1870,\n ~~~~~~~~~~~~~\n publishingCompany: 'PublisherBooks',\n ~~~~~~~~~~~~~~~~~\n copies: 1800,\n ~~~~~~\n availability: true,\n ~~~~~~~~~~~~\n status: 'ENABLED',\n ~~~~~~\n coverImage: [\n ~~~~~~~~~~\n 'cover1.jpg',\n 'cover2.jpg'\n ],\n categories: {\n ~~~~~~~~~~\n id: 24,\n name: 'Tech'\n },\n createdBy: {\n ~~~~~~~~~\n connect: {\n id: 1\n }\n },\n + name: String,\n ? books?: {\n ? create?: BookCreateWithoutCategoriesInput,\n ? connect?: BookWhereUniqueInput\n ? }\n }\n })\n\nUnknown arg `title` in data.title for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `author` in data.author for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `publishedYear` in data.publishedYear for type CategoryCreateInput. Did you mean `select`?\nUnknown arg `publishingCompany` in data.publishingCompany for type CategoryCreateInput.\nUnknown arg `copies` in data.copies for type CategoryCreateInput. Did you mean `books`?\nUnknown arg `availability` in data.availability for type CategoryCreateInput. Did you mean `select`?\nUnknown arg `status` in data.status for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `coverImage` in data.coverImage for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `categories` in data.categories for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `createdBy` in data.createdBy for type CategoryCreateInput. Did you mean `name`?\nArgument name for data.name is missing.\n\nNote: Lines with + are required, lines with ? are optional.\n",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"newBook"
]
}
],
"data": {
"newBook": null
}
}
}
schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator prisma_client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
role RoleUser @default(DEFAULT)
firstName String
lastName String?
email String @unique
password String
books Book[]
}
model Book {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String @unique
userId Int
author String[]
publishedYear Int
publishingCompany String
copies Int
availability Boolean
status RoleBookStatus @default(ENABLED)
coverImage String[]
categories Category[] @relation(references: [id])
createdBy User @relation(fields: [userId], references: [id])
}
model Category {
id Int @id @default(autoincrement())
name String @unique
books Book[] @relation(references: [id])
}
enum RoleUser {
ADMIN
DEFAULT
MANAGER
}
enum RoleBookStatus {
BLOCKED
BORROWED
DAMAGED
ENABLED
UNENABLED
}
Book.tsAlex Vilchis
07/09/2020, 1:23 AMNODE_ENV
to production
causes the server to not listen to any requests (502). Does anyone know why?Matt
07/09/2020, 1:30 AMconst GQLDateTime = asNexusMethod(GraphQLDateTime, "datetime");
^
TypeError: asNexusMethod is not a function
I still have
const { asNexusMethod } = require("nexus");
in the code above the line where I'm using it. Any idea what's causing the issue?Andrew Leung
07/09/2020, 9:24 PMGraphQLSchema
produced by the framework?
An example would be when trying to implement Subscriptions
and using subscriptions-transport-ws
web sockets.
The excerpt from the README:
import { createServer } from 'http';
import { SubscriptionServer } from 'subscriptions-transport-ws';
import { execute, subscribe } from 'graphql';
import { schema } from './my-schema';
const WS_PORT = 5000;
// Create WebSocket listener server
const websocketServer = createServer((request, response) => {
response.writeHead(404);
response.end();
});
// Bind it to port and start listening
websocketServer.listen(WS_PORT, () => console.log(
`Websocket Server is now running on <http://localhost>:${WS_PORT}`
));
const subscriptionServer = SubscriptionServer.create(
{
schema,
execute,
subscribe,
},
{
server: websocketServer,
path: '/graphql',
},
);
In order to get SubscriptionServer
working, it requires the GraphQLSchema
to be passed through.Henry
07/14/2020, 3:00 PMPani Avula
07/15/2020, 6:38 AMPeter
07/15/2020, 6:11 PMPackage.json version field is not a string
I also can’t report an issue on github 😢Martin Nirtl
07/17/2020, 12:26 PMMichael
07/18/2020, 6:45 AMError: node_modules/@types/typegen-nexus-context/index.d.ts:5:10 - error TS2459: Module '"../../../src/app"' declares 'Prisma' locally, but it is not exported.
(+ another typescript error) though.Michael
07/19/2020, 9:45 AMpal g
inside the folder, I do get ✕ Error: @prisma/client is not found
. Sounds like it's assumed in the local node_modules
folder and not the monorepo's one.Peter
07/20/2020, 1:08 PMryan
07/20/2020, 3:31 PMMichael
07/20/2020, 4:00 PMpaljs
to be a very promising project, I think the CRUD that it generates does not fit to react-admin.
Things get complicated because of a newer version of nexus-prisma (now nexus-plugin-prisma). so that the examples in react-admin are not up to date enough anymore.
Does anyone have a up to date template for this architecture?
I'm a bit irritated, why it's so hard to find something like this. It makes me wonder if my choices are to exotic. But from what I read prisma is widely used plus react-admin is maybe the admin framework with the most traction currently. I may be wrong, any hints welcome.jasonkuhrt
Michael
07/21/2020, 10:05 AM- Missing type DateTime, did you forget to import a type to the root query?
Will post the whole file in a thread to the right.Michael
07/21/2020, 11:31 AM- Missing type ActorWhereInput, did you forget to import a type to the root query?
(only when addCrudResolvers("Actor"),
is added)
the server does not start, that wasn't the case before. does anyone have a hint what could be the issue here?Michael
07/21/2020, 11:38 AMPeter
07/21/2020, 1:15 PMmodel EventCost {
id String @id @default(uuid())
amount Int
cost Int
eventTypes EventType @relation(fields: [eventTypeId], references: [id])
eventTypeId String
}
model EventType {
id String @id @default(uuid())
name String
visible Boolean
duration Int
eventCosts EventCost[]
}
I also try to create type by nexus
schema.objectType({
name: 'EventType',
definition(t) {
t.model.id()
t.model.name()
t.model.visible()
t.model.duration()
t.field('eventCosts', { type: 'EventCost' })
},
})
but I got error that
Type '"EventCost"' is not assignable to type ....
When I’m checking generated schema I getting something like this
type EventType {
duration: Int!
eventCosts: NEXUS__UNKNOWN__TYPE
id: String!
name: String!
visible: Boolean!
}
scalar NEXUS__UNKNOWN__TYPE
I run migration and rerun the nexus server but still missing the EventCost :|Awey
07/21/2020, 7:09 PMProperty 'query' does not exist on type 'NexusTestContextApp'.ts(2339)
Not sure if I'm doing something wrong or if the tutorial is outdated/wrong. I pretty much copy pasted all the code it gave and there is still an error.Peter
07/21/2020, 7:27 PMAwey
07/21/2020, 7:56 PMx
beside JS support. Does that mean everything needs to be written in TS?Awey
07/21/2020, 10:43 PMAwey
07/21/2020, 10:50 PMimport * as
or else it will not work. If anyone can explain to me why that is, I'd really appreciate it.Awey
07/21/2020, 11:02 PM