Prisma deploy: relations are expected for enums/expecting an interface, directive or definition - graphql

I'm trying to deploy my updated datamodel.prisma file. However, an error occurs and from what I can understand, it thinks that I'm trying to create a relation between an enum I defined above with the User type.
Here is my file:
enum Permission {
ADMIN
USER
ITEMCREATE
ITEMUPDATE
ITEMDELETE
PERMISSIONUPDATE
}
type User {
id: ID! #id
name: String!
email: String! #unique
password: String!
resetToken: String
resetTokenExpiry: String
permissions: [Permission]
}
type Item {
id: ID! #id
title: String!
description: String!
image: String
largeImage: String
price: Int!
createdAt: DateTime! #createdAt
updatedAt: DateTime! #updatedAt
}
Running prisma deploy --env-file variables.env gives me this error below:
Errors:
User
✖ Valid values for the strategy argument of `#scalarList` are: RELATION.
If I change permissions: [Permission] to permissions: Permission[], it gives this error instead (specifically, expected ImplementsInterfaces, DirectivesConst or FieldDefinitions):
ERROR: Syntax error while parsing GraphQL query. Invalid input "{\n id: ID! #id\n name: String!\n email: String! #unique\n password: String!\n resetToken: String\n resetTokenExpiry: String\n permissions: Permission[", expected ImplementsInterfaces, DirectivesConst or FieldDefinitions (line 10, column 11):
type User {
^
{
"data": {
"deploy": null
},
"errors": [
{
"locations": [
{
"line": 2,
"column": 9
}
],
"path": [
"deploy"
],
"code": 3017,
"message": "Syntax error while parsing GraphQL query. Invalid input \"{\\n id: ID! #id\\n name: String!\\n email: String! #unique\\n password: String!\\n resetToken: String\\n resetTokenExpiry: String\\n permissions: Permission[\", expected ImplementsInterfaces, DirectivesConst or FieldDefinitions (line 10, column 11):\ntype User {\n ^",
"requestId": "us1:ck6au2sum8frx0b00fviv1dom"
}
],
"status": 200
}
I'm not sure what that error means, but I do have a feeling that it doesn't understand the #unique type modifier at the email field. It wasn't there previously and deploys worked fine. Any help is greatly appreciated!

You need to specify the strategy and #scalarList directive.
This #scalarList(strategy: STRATEGY!) directive is required on any
scalar list field. The only valid argument for the strategy argument
is RELATION.
type Post {
tags: [String!]! #scalarList(strategy: RELATION)
}
It is required for all scalar and enum list fields.
See: https://www.prisma.io/docs/datamodel-and-migrations/datamodel-MYSQL-knul/##scalarlist

Related

Cannot read properties of null (reading '_doc')

I'm running a query in GraphQL and getting this error:
{
"errors": [
{
"message": "Cannot read properties of null (reading '_doc')",
"locations": [
{
"line": 38,
"column": 5
}
],
"path": [
"songs",
0,
"creator"
]
}
],
"data": null
}
This is the query.
query {
songs {
song_file_name
song_type
song_size
user_name
creator {
email
}
This is my resolver file, and this is the schema.
const { buildSchema } = require('graphql');
module.exports = buildSchema(`
type Song {
_id: ID!
song_file_name: String!
song_type: String!
song_size: Int!
user_name: String!
creator: User!
}
type User {
_id: ID!
email: String!
password: String
createdSongs: [Song!]
}
input SongInput {
song_file_name: String!
song_type: String!
song_size: Int!
user_name: String!
}
input UserInput {
email: String!
password: String!
}
type RootQuery {
songs: [Song!]!
}
type RootMutation {
createSong(songInput: SongInput): Song
createUser(userInput: UserInput): User
}
schema {
query: RootQuery
mutation: RootMutation
}
`);
Could anyone help me figure out what I'm doing wrong? It looks like creator is returning null, but it is properly defined as far as I can tell. What's causing this?
Also, can anyone suggest a good place to learn GraphQL? I'm following this guide and though I find it useful and informative, it quickly gets to a level where I don't feel I fully understand what I'm doing although I'm following along.
I know the basics of GraphQL, but the relational concepts is hard for me to wrap my head around.

Authorization error when updating a GraphQL object using aws-amplify

I'm experiencing issues when using aws amplify to generate a graphql API
My model has mainly two objects (User and messages):
User object:
type User
#model(subscriptions: null)
#auth(rules: [{ allow: owner, ownerField: "id" }]) {
id: ID!
email: String!
username: String!
avatar: S3Object
name: String
conversations: [Conversation] #manyToMany(relationName: "UserConversations")
messages: [Message!]! #hasMany(indexName: "byAuthor", fields: ["id"])
createdAt: String
updatedAt: String
}
Message object:
type Message
#model(subscriptions: null)
#auth(
rules: [
{
allow: owner
ownerField: "authorId"
operations: [create, update, delete]
}
]
) {
id: ID!
author: User #belongsTo(fields: ["authorId"])
authorId: ID! #index(name: "byAuthor", sortKeyFields: ["content"])
content: String!
conversation: Conversation! #belongsTo(fields: ["messageConversationId"])
messageConversationId: ID!
#index(name: "byConversation", sortKeyFields: ["createdAt"])
createdAt: String
updatedAt: String
}
There's a hasMany/belongsTo relationship between the two and auth rules on both.
After I signin to the API and try to create a user object through the JS API, i'm getting the following error
'Not Authorized to access messages on type ModelMessageConnection'
await AuthAPI.graphql(
graphqlOperation(createUser, {
input: {
id,
username,
email,
name,
},
})
);
This is actually due to the message rule that was missing the read action. Changing the object model to the code below fixed it
type Message
#model(subscriptions: null)
#auth(
rules: [
{
allow: owner
ownerField: "authorId"
operations: [create, update, delete, read]
}
]
) {
id: ID!
author: User #belongsTo(fields: ["authorId"])
authorId: ID! #index(name: "byAuthor", sortKeyFields: ["content"])
content: String!
conversation: Conversation! #belongsTo(fields: ["messageConversationId"])
messageConversationId: ID!
#index(name: "byConversation", sortKeyFields: ["createdAt"])
createdAt: String
updatedAt: String
}

No directive found for `bcrypt`

I'm following official Lighthouse documentation on how to setup GraphQl into my project.
Unfortunately, I'm stacked with the following error:
No directive found for `bcrypt`
Following schema I have created so far:
type Query {
users: [User!]! #paginate(defaultCount: 10)
user(id: ID #eq): User #find
}
type User {
id: ID!
name: String!
email: String!
created_at: DateTime!
updated_at: DateTime!
}
type Mutation {
createUser(
name: String!,
email: String! #rules(apply: ["email", "unique:users"])
password: String! #bcrypt
): User #create
}
The query I'm trying to execute is following:
mutation {
createUser(
name:"John Doe"
email:"john#test.com"
password: "somesupersecret"
) {
id
email
}
}
Okay dug up - there is no more #brypt directory in \vendor\nuwave\lighthouse\src\Schema\Directives\ instead, there is #hash directive which is working like a charm and uses driver you specify in config/hashing.php configuration file

Graphql with mutation spring boot

My schema file is
type Mutation {
createCustomer(name: String!, email: String!, product: [Product]): Customer
}
input Product {
id: ID!
name: String!
price: Int
}
interface Person {
id: ID!
name: String!
email: String!
}
type Customer implements Person {
id: ID!
name: String!
email: String!
product: [Product]
}
I want to insert customer detail here which has product list as input. My query is
mutation {
createCustomer(
name: "kitte",
email: "kitte#gmail.com",
product: [
{
name: "soap",
price: 435,
}
]
)
{
id
name
email
product{name}
}
}
But I am getting exception
{
"data": null,
"errors": [
{
"validationErrorType": "WrongType",
"message": "Validation error of type WrongType: argument value ArrayValue{values=[ObjectValue{objectFields=[ObjectField{name='name', value=StringValue{value='dars76788hi'}}, ObjectField{name='price', value=IntValue{value=123}}]}, ObjectValue{objectFields=[ObjectField{name='name', value=StringValue{value='darr'}}, ObjectField{name='price', value=IntValue{value=145}}]}]} has wrong type",
"locations": [
{
"line": 5,
"column": 5
}
],
"errorType": "ValidationError"
}
]
}
I don't understand what is the error. And how to pass list to mutation. I have referred some examples but not able to insert product as list.
Make sure you are passing the right type of objects to your mutation. GraphQL needs separate types for input fields. In your schema, Product types should be something like this and you should change the mutation accordingly.
type Product {
id: ID!
name: String!
price: Int
}
input ProductInput {
name: String!
price: Int
}
input CustomerInput {
...
products: [ProductInput]
}
There are couple of very useful examples in the docs, see Mutations and Input Types

GraphQL error: Unknown argument 'deleted' on field 'removeFromPostsOnComments'

So, I have a one to many relationship from Posts to comments:
type Comments {
createdAt: DateTime!
deleted: Boolean
id: ID!
posts: Posts #relation(name: "PostsOnComments")
text: String!
updatedAt: DateTime!
user: String!
}
type Posts {
caption: String!
comments: [Comments!]! #relation(name: "PostsOnComments")
createdAt: DateTime!
displaysrc: String!
id: ID!
likes: Int
updatedAt: DateTime!
}
and wish to run a mutation, which as well as deleting the connection between a post and a comment, attempts to update the field 'deleted, on Comments, to true:
mutation removeComment ($id: ID!, $cid: ID!, $stateB: Boolean) {
removeFromPostsOnComments (postsPostsId: $id, commentsCommentsId: $cid, deleted: $stateB){
postsPosts {
__typename
id
comments {
__typename
id
text
user
deleted
posts {
__typename
id
}
}
}
}
}
Query Variables
{
"id": "cj0qkl04vep8k0177tky596og",
"cid": "cj1de905k8ya201934l84c3id"
}
But when I run the mutation I get the following error message:
GraphQL error: Unknown argument 'deleted' on field 'removeFromPostsOnComments' of type 'Mutation'. (line 2, column 74):
removeFromPostsOnComments(postsPostsId: $id, commentsCommentsId: $cid, deleted: $stateB) {
As was explained to me here, only the link between Posts and comments is deleted, not the actual 'Comment' record itself. So my thinking is, as the record is not deleted, why can I not update the 'deleted' field?
I wish to do this so that it triggers a subscription, which is monitoring the updated field 'deleted'.
The generated mutation output is as follows:
"data": null,
"errors": [
{
"message": "Unknown argument 'deleted' on field 'removeFromPostsOnComments' of type 'Mutation'. (line 2, column 77):\n removeFromPostsOnComments (postsPostsId: $id, commentsCommentsId: $cid, deleted: $stateB){\n ^",
"locations": [
{
"line": 2,
"column": 77
}
]
}
]
}
As can be seen in the image, 'deleted' is definitely included in 'Comments' my GraphCool schema:
I reproduced your issue. First of all, you're getting the error message because deleted is not part of the arguments of the removeFromPostsOnComments-mutation, you also see that in the docs:
If you want to update the deleted field on the Comments type, you have to use the updateComments-mutation:
mutation {
updateComments(id: "cj1de905k8ya201934l84c3id", deleted: true) {
id
}
}

Resources