No directive found for `bcrypt` - laravel

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

Related

Using graphql, I need to crate a mutation which includes an empty array

Below, I'm attempting to create a type Customer which will include and array of type Box.
In my addCustomer mutation, I need to create an empty boxes array which will later have Boxes pushed into to it. I'm getting this error:
Error: The type of Mutation.addCustomer(boxes:) must be Input Type but got: [Box].
Any ideas?
const { gql } = require('apollo-server-express');
const typeDefs = gql`
type Customer {
_id: ID
firstName: String
lastName: String
email: String
password: String
address: String
city: String
state: String
zip: String
phone: String
boxes: [Box]
}
type Auth {
token: ID!
customer: Customer
}
type Box {
_id: ID!
boxSize: String!
sendToCustomer: Boolean!
getFromCustomer: Boolean!
}
type Mutation {
addCustomer(
firstName: String!,
lastName: String!,
email: String!,
password: String!,
address: String!,
city: String!,
state: String!,
zip: String!,
phone: String!
boxes: [Box]
): Auth
login(email: String!, password: String!): Auth
createBox(
boxSize: String!,
sendToCustomer: Boolean!,
getFromCustomer: Boolean!
): Box
addBoxToCustomer(
customerId: ID!,
boxSize: String!,
sendToCustomer: Boolean!,
getFromCustomer: Boolean!
): Customer
}
In GraphQL Input Object Types and Object Types are not compatible. This means that you can't use an output object type as an input object type, even if they have the same structure.
For customer you have circumvented the problem by defining every field as an argument to the mutation. First, I would create an Box input type. I like to call these input types drafts and postfix them with Draft but many people in the community postfix with Input.
input BoxDraft {
boxSize: String!
sendToCustomer: Boolean!
getFromCustomer: Boolean!
}
Notice how we can leave out the _id field, as I assume it is automatically generated by your server implementation. Then you can reference this type in your mutation.
type Mutation {
addCustomer(
firstName: String!,
lastName: String!,
email: String!,
password: String!,
address: String!,
city: String!,
state: String!,
zip: String!,
phone: String!
boxes: [BoxDraft]
): Auth
# ...
}
I would go even one step further and also define a draft type for Customer:
input CustomerDraft {
firstName: String!
lastName: String!
email: String!
password: String!
address: String!
city: String!
state: String!
zip: String!
phone: String!
boxes: [BoxDraft]
}
type Mutation {
addCustomer(draft: CustomerDraft!): Auth
}

GraphQL - Model(s) belong to specific user field

I'm using Lighthouse package to implement GraphQL, the users in my app belong to an entity and I need to get models that belong to the entity of each user, my schema is like this for the moment
"A date string with format `Y-m-d`, e.g. `2011-05-23`."
scalar Date #scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date")
"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")
type Query {
me: User #auth
execution: [RobotTime!]! #all
}
type RobotTime {
id: ID!
instance: Instance!
robot: Robot!
start: DateTime!
end: DateTime!
}
type Instance {
id: ID!
name: String!
token: String!
}
type Robot {
id: ID!
start_bot: String!
process: Process!
}
type Process {
id: ID!
name: String!
token: String!
}
type User {
id: ID!
name: String!
email: String!
created_at: String!
updated_at: String
}
I have searched the documentation, but I can't find anything that helps me to do what I need to do.
Currently I have it done in a controller and I return it as a json with a not so complex logic, there are about 5 models that I use.
Sorry for my bad English
You need to declare the appropriate relation in your User model in laravel, sth like this:
public function entity(): BelongsTo
{
return $this->belongsTo(Entity::class);
}
Then add the relation in User type in graphql:
type User {
id: ID!
name: String!
email: String!
created_at: DateTime!
updated_at: DateTime
entity: Entity #belongsTo
}
Of course, you'll need to declare an Entity model in laravel and type in graphql.

GraphQL convention for querying by ID or path

Assume you have a schema where a resource can be identified by its ID or a path (/userName/projectName):
type User {
id: ID!
name: String!
}
type Project {
id: ID!
name: String!
owner: User!
}
To query a project, we need two resolvers:
findProjectByID(id: String!): Project!
findProjectByPath(userName: String!, projectName: String!): Project!
Ideally, we'd have just one resolver that accepts both kinds of identifiers:
findProject(???): Project!
These are the ideas I can come up with, but none of them seem very neat:
# Idea 1
findProject(idOrPath: String!): Project!
# Idea 2
findProject(id: String, userName: String, projectName: String): Project!
# Idea 3
findProject(identifier: ProjectIdentifier): Project!
union ProjectIdentifier = ProjectID | ProjectPath
type ProjectID { id: String! }
type ProjectPath { userName: String!, projectName: String! }
What would be the most GraphQL-y approach? Is there a convention that applies here?

Filter by Email in prisma GraphQL

I'm trying to filter a user by email, I am using prisma and doing tests with the "playground", is there any way to filter the user's data by email?
My schema:
interface Model {
id: ID! #id
createdAt: DateTime! #createdAt
updatedAt: DateTime! #updatedAt
}
type User implements Model {
id: ID! #id
createdAt: DateTime! #createdAt
updatedAt: DateTime! #updatedAt
username: String
name: String!
surname: String!
email: String!
token_usuario: String! #unique
}
My attempts:
Using prisma 2.0, the db client exposes something like this:
ctx.prisma.user.findMany({
where: {
email: { contains: "something" }
}
});
And I expect the query would follow suit. So try passing in the where field for filtering. Would need to see the full schema to say for sure.

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