Can't create type with ‘id: ID! #unique’ - prisma

I just setup the advanced boilerplate with the init command and added the following to datamodel.graphql
type Spot {
id: ID! #unique
createdAt: DateTime!
updatedAt: DateTime!
lat: String!
long: String!
name: String!
fishes: [Species!]!
}
type Species {
id: ID! #unique
createdAt: DateTime!
updatedAt: DateTime!
name: String!
spots: [Spot!]!
}
When I try to do prisma deploy the public demo never starts up (500 error). As soon as I remove id: ID! #unique from type Species type it starts working. I tried doing prisma reset with the same issue. When I do prisma seed -r I get the following error message, note that seed.graphql just contains the boilerplate code.
ERROR: All fields within 'Query' type should have unique names! Non-unique fields: 'species'.
{
"errors": [
{
"message": "All fields within 'Query' type should have unique names! Non-unique fields: 'species'.",
"requestId": "us1:api:cjhobke57sxok0b62n6f96ez4"
}
],
"status": 500
}

Although I was unable to figure it out exactly, if I change out the word "Species" for any other word it works. My guess is that it does not know how to properly pluralize "Species".

Related

mapping Swift Set of struct objects to kotlin Set of data classes with Kotlin Multiplatform Mobile

For example, I've got this simple business code in kotlin:
class ProjectItemFacade(
val projects: Set<ProjectEntity>
) {
fun sortedProjects(): List<ProjectEntity> {
return projects.toList().sortedBy { it.name }
}
}
data class ProjectEntity(
val id: String,
val name: String,
val description: String
)
I try to call it from Swift like that:
struct ProjectItem: Identifiable, Codable, Hashable {
var id = UUID().uuidString
let name: String
let description: String
}
let projects: Set = [
ProjectItem(name: "Zero Project", description: "test1"),
ProjectItem(name: "First Project", description: "test2"),
ProjectItem(name: "Third Project", description: "test3"),
]
let sortedProjects = ProjectItemFacade(projects: projects).sortedProjects()
but it gives me an error:
Cannot convert value of type 'Set<ProjectItem>' to expected argument type 'Set<ProjectEntity>'
Cannot use instance member 'projects' within property initializer; property initializers run before 'self' is available
It seems like there is a problem with mapping Swift struct to kotlin data class. How to solve it?
EDIT
After renaming the kotlin class to the same as in swift it returns first error like that:
Cannot convert value of type 'Swift.Set<iosApp.ProjectItem>' to expected argument type 'Swift.Set<shared.ProjectItem>'
As #Sweeper said in comment, I should use kotlin class in my swift code. I decided to map my array like that:
import Foundation
import shared
struct ProjectItem: Identifiable, Codable, Hashable {
var id = UUID().uuidString
let name: String
let description: String
func toEntity() -> ProjectEntity {
ProjectEntity(id: id, name: name, description: description)
}
static func fromEntity(_ entity: ProjectEntity) -> ProjectItem {
ProjectItem(id: entity.id, name: entity.name, description: entity.description_)
}
}
Note that I use entity.description_ because it seems like description property call the data class toString() method.
let projects: Set = Set(
[
ProjectItem(name: "Zero Project", description: "test1"),
ProjectItem(name: "First Project", description: "test2"),
ProjectItem(name: "Third Project", description: "test3"),
]
.map { $0.toEntity() }
)
var sortedProjects: Array<ProjectEntity> {
get {
return ProjectItemFacade(projects: projects)
.sortedProjects()
}
}
Computed get solved the second error.

Why does collection.find_one({ _id: id }) always return nothing even with correct string id?

I am working on a MongoDB-based API webserver to learn Rust and I can't figure out why I can't get results:
use mongodb::bson::{doc, oid::ObjectId};
use mongodb::{error::Error, Database};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
struct Job {
_id: ObjectId,
user_id: String,
organisation: String,
role: String,
}
async fn find_job_by_id(database: &Database, id: String) -> Result<Option<Job>, Error> {
database
.collection("jobs")
.find_one(Some(doc! { "_id": id }), None)
.await
}
I've tried printing out the id at every step and it always looks correct, but .find_one() always returns Ok(None). Any tips?
Turns out filters for ObjectId fields have to be specifically use ObjectId. You can't apply filters using strings as I was doing over there. This method is what fixed it:
let id = ObjectId::parse_str(id).unwrap();
Looks like the myths were true... rust is pretty harsh with type checking...

How to upload files in a GraphQL mutation nested inputs?

I'm new to GraphQL and trying to figure out how to upload multiple files in a nested inputs mutation.
input PostInputs {
id: ID!
name: String!
images: [ImageInputs!]!
}
input ImageInputs {
id: ID!
file: Upload!
alt_name: String!
}
type Mutation {
createPost(input: PostInputs! #spread): Post!
}
How to construct the mutation in playground?

Golang mongodb build reference relationship

I have this one-to-many reference relationship in graphql with Mongo go driver.
type User {
id: ObjectID!
email: String!
username: String!
posts: [Post!]!
}
type Post {
id: ObjectID!
author: User!
title: String!
content: String!
}
I know that I can use the Aggregate framework to query the reference relationship.
However, What should I do if I want to create a user at the same time also create a post?
Sending two collection.InsertOne in the resolver?

JSON Decoding UUID String to UUID Object

For some weird reason when decoding JSON which contains the UUID as String, the resultant UUID property is always coming to be nil.
UPDATE:
struct Movie: Codable {
var id: UUID?
var title: String
var poster: String
UPDATE:
This is unbelievable. Debugger was lying the value was NOT NULL.