A relation in graphcool makes fail the deploy for no reason - graphql

I created this relation in my graphcool
type User #model {
id: ID! #isUnique
location: Location! #relation(name: "UserLocation")
}
type Location #model {
id: ID! #isUnique
lat: Int
lng: Int
User: User! #relation(name: "UserLocation”)
}
Before location was a String, but now I wanted it to be an object so I created this relation, so that I can then use nested mutations. When I deploy I get this error:
There are issues with the new service definition:
Global
✖ None.get
I googled, looked on the documentation but I cannot understand what I am doing wrong, is a simple relation.

Faced issues like this when changing the type of fields as well. Not sure what the reason for this behavior (looks like it's a graphcool issue) but to solve them you can split it into two steps:
1) remove this relation from graphcool schema:
type User #model {
id: ID! #isUnique
# location: Location! #relation(name: "UserLocation")
}
type Location #model {
id: ID! #isUnique
lat: Int
lng: Int
# User: User! #relation(name: "UserLocation”)
}
2) revert relation fields with the new type:
type User #model {
id: ID! #isUnique
location: Location! #relation(name: "UserLocation")
}
type Location #model {
id: ID! #isUnique
lat: Int
lng: Int
User: User! #relation(name: "UserLocation”)
}

Related

AWS Amplify GraphQL Schema is causing an error

I am new to Amplify and I am trying to set up a fairly complex schema. When I run amplify push, the only response that I get is ...
An error occurred when pushing the resources to the cloud
This happens after the notice that it will create the resources and I am asked if I want to continue. I deleted most of the schema and tried again with just one model and it worked, so there is a problem somewhere in my schema ... I guess? I don't see anywhere to check it.
Here is the schema
type Article
#model
#key(name: "bySource", fields: ["sourceId", "dateWritten"]) {
id: ID!
link: AWSURL!
title: String!
dateWritten: String!
createdAt: String!
data: AWSJSON!
approved: Boolean!
admin: Boolean!
creatorId: ID!
creator: User #connection(fields: ["creatorId"])
sourceId: ID!
source: Source #connection(fields: ["sourceId"])
tagArtCons: [TagArtCon]
#connection(keyName: "byArticle", fields: ["articleId"])
}
type Tag #model #key(name: "byFrontPage", fields: ["frontpage"]) {
id: ID!
name: String!
createdAt: String!
creatorId: ID!
data: AWSJSON!
frontpage: String
official: Boolean!
tagArtConns: [TagArtCon] #connection(keyName: "byTag", fields: ["tagId"])
}
type TagArtCon
#model
#key(name: "byTag", fields: ["tagId"])
#key(name: "byArticle", fields: ["articleId"]) {
id: ID!
tagId: ID!
articleId: ID!
creatorId: ID!
createdAt: String!
article: Article #connection(fields: ["articleId"])
tag: Tag #connection(fields: ["tagId"])
parentRelations: [TagRelation]
#connection(keyName: "byParent", fields: ["tagId"])
childRelations: [TagRelation]
#connection(keyName: "byChild", fields: ["tagId"])
}
type TagRelation
#model
#key(name: "byParent", fields: ["parentId"])
#key(name: "byChild", fields: ["childId"]) {
id: ID!
parentId: ID!
childId: ID!
creatorId: ID!
createdAt: String!
parentTag: Tag #connection(fields: ["parentId"])
childTag: Tag #connection(fields: ["childId"])
}
type Source #model {
id: ID!
sourceName: String!
sourceUrl: String!
sourceImage: String!
creatorId: ID!
articles: [Article] #connection(keyName: "bySource", fields: ["id"])
}
type User #model {
id: ID!
userName: String!
userImage: String!
admin: Boolean!
createdAt: String!
data: AWSJSON
}
What I am trying to do is have a bunch of articles and a bunch of tags. The tags represent categories, people, etc. I have the following tables
articles,
tags,
a table where each entry ties an article to a tag
a table of relations between tags where parent/child relationships are held
a source table that just holds data for the sources of the articles
a user table
I've made a mistake somewhere and the schema isn't working and it isn't telling me why. I'm gonna keep simplifying this until I can hope to nail down the problem, but I would really appreciate any help as I am new to this. Thanks.
Finally found the problem(s). There is a place where I try to use "articleId" and a place where I try to use "tagId" and both should be "id".

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 Prisma - use orderBy on nested relationships

I am fairly new to GraphQL Prisma combo, I cannot seem to order nested relationships without error because the only available orderBy fields are regarding the ID.
My intended goal in the playground would be to create a query that looks similar to the following:
getPosts{
connections(orderBy: "text_asc"){
id
text
}
}
Resolver
getPosts(parent, args, ctx, info){
return ctx.db.query.posts({}, info)
}
Data Model
type Post {
id: ID! #id
isPublished: Boolean! #default(value: false)
title: String!
text: String!
connections: [Connection!]! #relation(name: "ClientConnect")
}
type Link {
id: ID! #id
text: String!
url: String!
}
type Connection {
id: ID! #unique #id
client: Link #relation(name: "LinkConnect")
}

GraphQL query for find equal field on realations

I have a schema for GraphQL like this (it's good to mention that I'm using Prisma) :
enum PollResult {
HOME_WIN
AWAY_WIN
DRAW
}
type UserPoll {
id: ID! #unique
user: User!
predict: PollResult!
}
type Poll {
id: ID! #unique
away: Team #relation(name: "AwayTeam")
home: Team #relation(name: "HomeTeam")
group: Group!
country: Country!
sport: Sport!
result: PollResult
state: PollState! #relation(name: "PollState")
users: [User] #relation(name: "Users")
usersPrediction: [UserPoll] #relation(name: "UserPoll")
}
as you see in UserPoll I have predict with type of PollResult and in Poll
I have result with the type of PollResult. now I want to query on Poll and find the specific user (with id or email) that has the same value of usersPrediction -> predict with Poll -> result.
one query that I try is something like this :
query{
userPolls(where:{user:{id:"someid"}}){
}
}
but here I don't know how to find users with equal predict with polls result.If it's the problem with my schema please let me know.
I can't think of a way to express that in a single query, but since you're using an Enum it would only be three similar queries.
query predict_HOME_WIN{
polls(where:{result: HOME_WIN}){
usersPrediction(where:{predict: HOME_WIN})
user{
id
}
}
}
This will give you all users that predicted a HOME_WIN when the result was a HOME_WIN. You could then do the same query for the other two enum values and sum up the results. Then you have all users who predicted the correct outcome. You could send the queries in one go to Prisma by naming them.
Hope that helps
Could you replace your usersPrediction field with three fields:
allUsersPrediction
rightUsersPrediction
wrongUsersPrediction
Then whole schema will be:
enum PollResult {
HOME_WIN
AWAY_WIN
DRAW
}
type UserPoll {
id: ID! #unique
user: User!
predict: PollResult!
}
type Poll {
id: ID! #unique
away: Team #relation(name: "AwayTeam")
home: Team #relation(name: "HomeTeam")
group: Group!
country: Country!
sport: Sport!
result: PollResult
state: PollState! #relation(name: "PollState")
users: [User] #relation(name: "Users")
allUsersPrediction: [UserPoll] #relation(name: "UserPoll")
rightUsersPrediction: [UserPoll] #relation(name: "UserPoll")
wrongUsersPrediction: [UserPoll] #relation(name: "UserPoll")
}
Required users will be at rightUsersPrediction[].user

authenticate user and serve only their related data

I have a schema in graphcool with these nodes (not sure what the correct term is here... leaf? node? model? type??)
type User #model {
auth0UserId: String #isUnique
createdAt: DateTime!
id: ID! #isUnique
userIdentifier: String
bundleIdentifier: String
updatedAt: DateTime!
devices: [Device!]! #relation(name: "UserOnDevice")
tokens: [Token!]! #relation(name: "TokenOnUser")
}
type Device #model {
id: ID! #isUnique
deviceIdentifier: String!
users: [User!]! #relation(name: "UserOnDevice")
token: Token #relation(name: "DeviceOnToken")
}
I'd like to make it so that a user must be authenticated and be related to the device data to be able to query on it. So, for a query like:
query($deviceIdentifier: String!) {
device(deviceIdentifier: $deviceIdentifier) {
id
}
}
This should return null unless they are autthenticated and are a user in the specified relation. I was thinking I needed a permission query like this one:
query ($node_id: ID!, $user_id: ID!) {
SomeDeviceExists(filter: {
id: $node_id,
users: {
id: $user_id
}
})
}
But it turns out that is invalid. How do I do it?
query ($node_id: ID!, $user_id: ID!) {
SomeDeviceExists(filter: {
id: $node_id,
users_some: {
id: $user_id
}
})
}
but this does require submitting the user_id in the request.

Resources