When I use #can in the query of getting all users like below I'm got an error that shows below:
getUsers(
first_name: String #like(template : "%{}%")
last_name: String #like(template : "%{}%")
email: String #like(template : "%{}%")
group_id: Int
# group_id: Group #belongsToMany(relation: "groups" )
orderBy: [OrderByClause!] #orderBy
): [User] #guard(with:["api"]) #can(ability: "getAllUser") #paginate(builder: "App\\GraphQL\\Queries\\User\\GetUsers#resolveUser")
and get this error:
"debugMessage": "Failed to find class UserPaginator in namespaces [App, App\\Models] for directive #can.",
This was fixed in v5.45.3 of Lighthouse
https://github.com/nuwave/lighthouse/releases/tag/v5.45.3
So you can fix your issue by simply updating Lighthouse.
Related
I have created the schema for my subgraph inside the .graphql file, here is a sample:
`
type Post #entity {
id: ID!
title: String! # string
body: String! # string
createdAt: BigInt! # uint256
groupID: BigInt! # uint256
}
type User #entity {
id: ID!
userId: BigInt!
transactionHash: Bytes
telephoneVerifiedData: String
email: String # string
_userAddress: Bytes
}
`
I tried making a schema for the query treating _userAddress field as a plain text (I don't know any other way, can't find anything in the docs):
type _Schema_
#fulltext(
name: "getUser"
language: simple
algorithm: rank
include: [
{ entity: "User", fields: [{ name: "userName", name: "_userAddress" }] }
]
)
but I get this message when deploying the subgraph:
✖ Failed to deploy to Graph node https://api.thegraph.com/deploy/: deployment failure::subgraph validation error: [schema validation failed: [FulltextIncludedFieldInvalid("_userAddress")]]
I see two issues.
In the fulltext query you specify userName as a field to search but it isn't defined on your User entity. Add userName: String to your User entity and
Second, the type of _userAddress is Bytes. In order for this field to be search it needs to be of type String.
Has anyone used this GraphQL Laravel Library before?
I managed to get it working on my local machine.
But when I deploy it to Heroku, I keep getting an error that my schema is not loaded.
How do I resolve this?
Here's a screenshot of my local GraphQL environment:
You may find the Heroku GraphQL Playground here.
I can't find much documentation on deploying GraphQL in PHP/Laravel online.
Thank you in advance for your help.
Edit:
Here is my schema:
"A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`."
scalar DateTime
#scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime")
"Indicates what fields are available at the top level of a query operation."
type Query {
"Gets a page."
pages(
"Filters by name. Accepts SQL LIKE wildcards `%` and `_`."
name: String #where(operator: "like")
): [Page!]! #paginate(defaultCount: 1)
"Gets a list of posts."
posts(
"Filters by featured property."
featured: Boolean
"Filter a single post by the slug"
slug: String
): [Post!]!
#paginate(defaultCount: 10)
#orderBy(column: "published_at", direction: DESC)
}
"A page of the blog."
type Page {
"Unique primary key."
id: ID!
"Name of the page. Used for filters"
name: String!
"Title of the page."
title: String!
"Subtitle of the page."
subtitle: String
"Head title of page."
metaTitle: String
"Head description of page."
metaDescription: String
}
"A blog post."
type Post {
"Unique primary key."
id: ID!
"Post's name. Used for filters."
name: String!
"Post's slug. Used for filters."
slug: String!
"Post's title."
title: String!
"Post's subtitle."
subtitle: String
"Post's short description."
summary: String
"Post's content."
text: String
"Post's head title."
metaTitle: String
"Post's head description."
metaDescription: String
"The date the post was published."
publishedAt: DateTime
}
Here are my Heroku configs:
Lighthouse is working fine. I think you have Introspection disabled on production, thats why GraphqlPlayground fails.
Is it possible in Laravel lighthouse GraphQL to query by relation table values?
For example, I have defined two types.
type Translation {
id: ID!
form_group_id: Int!
group: Group #hasOne
translation_key: String!
lv: String
en: String
ru: String
}
type Group {
id: ID!
name: String!
translations: [Translation]! #hasMany
}
and I want to query by group name.
The code below is just an example of the idea.
translation(group.name: String! #eq): Translation #find
I have an idea that this, can be possible with custom resolver, but is there a way using built in eloquent resolvers?
Event tho this is an experimental feature, you can use complex where conditions. This will allow you to fetch whatever type by its relation attributes. We use it on our application, and for the use we have, this is working as expected :)
I'm working on a GraphQL schema for my Laravel project using the lighthouse library. But I'm running into a problem when trying to validate the user confirmed their password. The issue occurs when I try to register a user. Consider the following type for my user
type User {
id: ID
first_name: String!
last_name: String!
email: String!
password: String!
phone_number: String
avatar: String
email_verified_at: DateTime
}
I try to register my user using the following mutation
extend type Mutation {
createUser(input: CreateUser #spread): User! #create
}
Where my CreateUser input looks like this
input CreateUser {
first_name: String!
last_name: String!
email: String! #rules(apply: ["email"])
password: String! #rules(apply: ["confirmed"])
phone_number: String
}
I get the expected error for my failed validation: "Validation failed for the field [createUser]" so that is fine. But when I try to add a password_confirmation within my request the following error is encountered: "Field \"password_confirmation\" is not defined by type CreateUser.". Thats when I thought I should add the password_confirmation field to the CreateUser input. But when I try that the validation passes but I get a database error that the password_confirmation is an Undefined column. Which makes sense because it isn't in my migration and I feel this shouldn't be required to be able to validate passwords.
tldr; How can I use the laravel confirmed validation within the lighthouse #rules directive
It is possible to override the fill function for the User model and manually unset the password_confirmation attribute:
public function fill(array $attributes)
{
unset($attributes['password_confirmation']);
return parent::fill($attributes);
}
The validation will run and the password_confirmation field will be unset before saving the model.
I currently using the github/graphql-client ruby gem to try and query my GraphQL API. Here is what I have.
module MyAPI
HTTP = GraphQL::Client::HTTP.new("http://myapi.com/graphql")
Schema = GraphQL::Client.load_schema(HTTP)
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
end
# Create the query.
CreateMeeting = MyAPI::Client.parse <<-'GRAPHQL'
mutation CreateMeeting($name: String!, $meeting_id: String!){
createMeeting(name: $name, meeting_id: $meeting_id){
name
}
}
GRAPHQL
meeting = {name: 'test', meeting_id: 'm_id'}
MyAPI::Client.query(CreateMeeting, meeting)
This give me back the following error:
unknown keywords: name, meeting_id
I'm not sure what's causing this, because within createMeeting on the API name and meeting_id are defined as String arguments.
Any help is appreciated!