I'm struggling with understanding how I can allow users to create new records in the list, but only allow creators to update their own posts.
E.g. the following structure:
post {
post1: {
author: "user1"
text: "Some text"
}
post2: {
author: "user2"
text: "Some text 2"
}
}
Here, I want both users to be able to create new posts. But also protect, say, post2 from being edited by user1. Thus, only user1 can edit post1 and only user2 can edit post2.
You'd want to do something like this:
{"rules": {
"post": {
"$id": {
".write": "auth !== null && (!data.exists() || data.child('author').val() === auth.uid)"
}
}
}}
Here you're only allowing write if the user is logged in and a) the node attempting to be written is empty or b) the node attempting to be written was authored by the current user.
Related
In pimcore I made several classes, and some classes are nested. In my example, there is a user object, the user has a questions property, which is also an object, and the questions object has also an answers array, in which are answers objects.
To get the data, the fetch request looks like this:
query {
getUser(id:19){id
username
password
points
ghostRecord
admin
character
questions{
... on object_question{
id
text
answered
points
answers{
... on object_answer{answer, correct}
}
}
}
}
How can I update the user or create a new user?
With mutation, I'm able to update the properties like username, or password like this:
mutation {
updateUser(id: 10, input: {
username: "Mike", points:"3", answers:${newAnswersObj}
}
) {
success
output {
modificationDate
}
}
}
But how can I update the questions and answers objects?
Is it even possible? Thanks in advance!
mutation {
updateUser(id: 10, input: {
username: "Mike", points:"3", answers:${newAnswersObj}
}
) {
success
output {
modificationDate
}
}
}
This above doesn't work.
I am new to GraphQL and Dgraph and have been reading through the manual.
I am following an example in the manual posted here:
https://dgraph.io/docs/graphql/schema/types/#union-type
I am seeking to use a mutation to add a node or list of Nodes and associate them as members acceptable within the addHome input function.
These nodes are however also of type Union and so I need to somehow cast the HomeMember to a Dog and define the category as an animal.
I see someone posted something here but i can't pull the pieces together since the code it suggests appears to already have been generated by DGraph:
https://discuss.dgraph.io/t/union-types-in-graphql/9581
I am unsure but have a feeling I perhaps need to somehow override the input HomeMemberRef which is automatically generated into the schema by DGraph and disable both parrot and human ?
My code so far looks like this:
mutation {
addHome(input: [
{address: "London",
// Here I need to add something a member that casts the
// HomeMember to a Dog, defines the category as an animal and is accepted within
// this addHome input function
}
]) {
home{
address
id
members
}
}
}
Found the answer posted on another page:
https://dgraph.io/docs/graphql/mutations/mutations-overview/
My GraphQL works using this:
mutation {
addHome(input: [
{address: "London",
members: [
{ dogRef: { category: Mammal, breed: "German Shepherd"} },
]
}
]) {
home {
address
members {
... on Dog {
breed
}
... on Parrot {
repeatsWords
}
... on Human {
name
}
}
}
}
}
Or in other words: How can I create a new entry that has a relationship with a specific collection and only with it?
The following code creates a new entry of the type Brand. How can I place it inside a specific collection?
I'm new to graphql, so if what I would like to achieve is not possible at all or not the way graphql works please tell me
Additional information:
I'm using mlab as my back end, and strapi (headless cms). On strapi I installed graphql as an external plugin.
Thanks in advance
mutation {
createBrand(input: {
data: {
name: "John",
description: "this is my description"
}
}) {
brand {
name
description
}
}
}
To my very limited understanding of graphql, I think that in order to associate a new entry with a specific collection you need to edit the code above and add:
mutation {
createBrand(input: {
data: {
name: "John",
description: "this is my description"
collectionInPlurals: ['collectionId']
}
}) {
brand {
name
description
}
}
}
collectioninPlurals for example could be items if the type of the collection is 'item' and then you provide the id of the specific item
I hope it could benefit others...
Is there a way to query reactions filtering on issue number and user?
{
repository(owner: "w3c", name: "webcomponents") {
issue(number: 688) {
title
reactions(last: 100) { <--- I want to filter on user here
edges {
node {
user {
login
}
content
id
}
}
}
}
}
}
https://developer.github.com/v4/explorer/
Not at the moment, but you can request this functionality by creating a new post here and tagging the post as a schema-request.
No, unfortunately github graphql api doesn't provide this capability to query reactions by known user in this context.
I'm developping a Loopback application extending base User model to UserCode model where each user is identified by an email plus a code fields.
So that a user can register with the same email twice but with different code.
I've seen that in node_modules/loopback/common/models/user.js at line 691 there is:
UserModel.validatesUniquenessOf('email', {message: 'Email already exists'});
I want to delete this restriction/validation but without change loopback code, of course.
How can I do it?
Maybe in the boot script I can loop through all validation and delete this one?
Figured it out
In this case you need to remove the default validations set by the User model
common/models/userCode.js
module.exports = function(UserCode){
//Add this line and it will start receiving multiple email.
delete UserCode.validations.email;
}
Also you can play with the required:true|false property to make any default defined property required or not.
common/models/userCode.json
{
"name": "UserCode",
"base": "User",
"idInjection": true,
"properties": {
"password": {
"type": "string",
"required": true
},
....
....
}
The following code the accepted answer will remove ALL the email validations:
module.exports = function(UserCode){
//Add this line and it will start receiving multiple email.
delete UserCode.validations.email;
}
Instead be selective and do something like this:
module.exports = function(UserCode){
// remove ONLY email uniqueness validation
UserCode.validations.email = UserCode.validations.email.reduce((all, one) => {
if (one.validation !== 'uniqueness') {
all.push(one);
}
return all;
}, []);
}