I have a graphql schema
type Post {
id: ID! #unique
createdAt: DateTime!
updatedAt: DateTime!
tags:[Tag!]!
}
type Tag {
id: ID! #unique
createdAt: DateTime!
updatedAt: DateTime!
name: String!
posts:[Post!]!
}
So, a tag can be applied to many posts and a post can have many tags.
Prisma generates code without any issues, but running a graphql server gives
Error: Unknown type "TagOrderByInput". Did you mean "PostOrderByInput", "UserOrderByInput", "LikeOrderByInput", "TagWhereInput", or "CommentOrderByInput"?
at assertValidSDL (/home/andriy/app/apollo/prisma/node_modules/graphql/validation/validate.js:89:11)
I am using docker with Prisma and Mysql. Is it possible to have such a relationship? If so what I am doing wrong?
The solution was that in schema.graphql I have imported
# import Post, Query.postsConnection, Post.PostOrderByInput from "./generated-
schema.graphql"
And by deleting Post.PostOrderByInput the error disappeared.
# import Post, Query.postsConnection from "./generated-
schema.graphql"
Related
I have a schema like this
type Store #model #key(name: "storesByDate", fields: ["type", "createdAt"], queryField: "storesByDate") #auth(rules: [{allow: private, operations: [read]}, {allow: groups, groups: ["Administrators"], operations: [read, create, update, delete]}]) {
id: ID!
name: String!
type: String!
description: String
createdAt: String!
Products: [Products] #connection(keyName: "byStore", fields: ["id"])
}
I added amplify to my project and it generated models like this with these errors
I don't think I am supposed to edit these files as they are auto generated. But can't understand why it generating wrong codes?
Please help
I've got two models: Note and Profile. Note contains foreign key of connected profile as you can see below.
Note: {
profile_id: String,
date: String,
content: String,
}
Profile: {
id: String,
name: String,
profilePicture: String
}
I want to get all notes and also name and profile picture of note.
In this situation should I:
get all notes and all profiles and then join them locally in for loop,
get all notes and then in for loop ask DB for name and picture of matching profile,
other option
Which way is recomended?
Take a look at mongoose's Populate. You can declare a Schema property with type: Schema.Types.ObjectId, ref: 'Profile'. When you run a Query you can .populate() this field with the corresponding document.
I am having trouble understanding the proper way to implement a MongoDB User record type, to use with GraphQL. Specifically, it has to do with the user id.
I would like to be able to query for a user record and get a user id as 'id'. MongoDB records have a _id by default.
How do I accomplish this?
do I have to define the user record as:
type User {
id: ID!
name: String!
email: String!
}
Should I then populate the 'id' field on my own when creating a record?
Or should I just use the _id as a user id? if so, how do I query it? I get issues saying that I cannot query it. I think because it's not in the typedef.
I'm using TypeGraphQL along with TypeORM, and there you can create mapping by using decorators:
#Field(type => ID!, { name: 'id' })
#Column({ type: '_id', nullable: false, unique: true })
public _id: string;
I want to filter in prisma for a relation id and get the same entity, not the related one back. Simple example:
type User {
firstName: String!
lastName: String!
isOwner: [Meta!]! #relation(link: INLINE, name: "User_Meta_Owner")
id: ID! #id
}
type Meta {
owner: User! #relation(link: INLINE, name: "User_Meta_Owner")
area: Area! #relation(link: INLINE, name: "Meta_Area")
id: ID! #id
}
type Area {
id: ID! #id
name: String!
meta: Meta! #relation(link: INLINE, name: "Meta_Area")
}
In this case i want all Meta entities which have an owner with the id userID and an Area with the id areaID.
What is possible:
ctx.db.user({ id: 'userID' }).isOwner()
This gets all Meta without a filter for the area.
What i want is something like:
ctx.db.user({ id: 'userID' }).isOwner({ where: { area: 'areaID' })
ctx.db.metas({ where: [{ owner: 'userID' }, { area: 'areaID' }] })
Since the property area is only a relation, prisma doesnt give me the opportunity to filter or even get the ids.
ie:
await ctx.db.user({ id: 'userID' }).isOwner()
will result in an array of objects like:
[{
id: '...'
}]
My question is, is there any way to get my wanted result without deleting the relation and store simple strings?
I got an answer from prisma member to get this currently only working with model like this:
type Meta {
owner: User! #relation(link: INLINE, name: "User_Meta_Owner")
area: Area! #relation(link: INLINE, name: "Meta_Area")
ownerId: ID! #db(name: "User")
areaId: ID! #db(name:"Area")
id: ID! #id
}
So the id's needs to be exposed as scalars, so you can filter those.
I am building a graphQL api with schema and annotations to use AWS Amplify's GraphQL transform. How can I control what kind of ES index it produces behind the scene?
This is a simple API that provides search functionality based on the, lets say, "5 km radius from the current location", timestamp and other keywords. The keywords search work absolutely fine but not the geospatial search. As per my research, for doing geospatial search, one needs to have a specific type of schema in ES. Here is my schema:
type User #model {
id: ID!
deviceID: [String!]
posts: [Post] #connection(name: "UserPosts")
comments: [Comment] #connection(name: "UserComments")
}
type Post #model #searchable {
id: ID!
items: String!
latitude: Float
longitude: Float
user: User #connection(name: "UserPosts")
comments: [Comment] #connection(name: "PostComments")
}
type Comment #model {
id: ID!
content: String
timestamp: AWSDateTime
location: String
post: Post #connection(name: "PostComments")
user: User #connection(name: "UserComments")
}
The query with lat, lon and distance to find "Posts" should return valid results.
The short answer to that is no.
The #searchable annotation and AppSyncs functionalities within ES are super limited out of the box. You can't even pass in fuzzy_matches.
I guess the way to go is to implement it yourself. You can modify the resolvers and thus also modify the ES search query. However, the resolvers are written in VST. Which might be not so easy to dig in.