Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-24-2019 03:13 AM
Hi,
I have a mutation createaAccess that creates a HAS_ACCESS_TO relationship between 2 nodes. This works fine.
createaAccess(user: ID!, entity_role: [String]!, application_role: [String]!, entity: Int!): WorkstationUser
@cypher(
statement:"""
MATCH (from:WorkstationUser {id: $user})
MATCH (to {id: $entity})
SET to:Entity
MERGE (from)-[:HAS_ACCESS_TO {application_role: $application_role, entity_role: $entity_role} ]->(to)
RETURN from
""")
I was wondering if there was a way to send user Object instead of id? One of the Apollo graphql tutorial says it can be done. Ref https://www.apollographql.com/docs/ios/mutations#input-objects
But If I change the mutation schema to
createaAccess(user: WorkstationUser!, entity_role: [String]!, ....
It gives me validation error when parsing schema on load itself.
[nodemon] starting `node src/index.js`
D:\graphqlws\graphql-graphdb\node_modules\graphql\type\validate.js:80
throw new Error(errors.map(function (error) {
^
Error: The type of Mutation.createaAccess(user:) must be Input Type but got: WorkstationUser!.
at assertValidSchema (D:\graphqlws\graphql-graphdb\node_modules\graphql\type\validate.js:80:11)
Solved! Go to Solution.
04-24-2019 10:18 AM
Yes that should work, but you'll need to declare an input type in your GraphQL type definitions to use for the argument:
input WorkstationUserInput {
id: ID!
name: String
...
}
then your mutation is something like this, where the input type becomes an object Cypher parameter:
createAccess(user: WorkstationUserInput, ...): WorkstationUser @cypher(statement:
"""
MATCH (from:WorkstationUser {id: $user.id})
....
"""
04-24-2019 10:18 AM
Yes that should work, but you'll need to declare an input type in your GraphQL type definitions to use for the argument:
input WorkstationUserInput {
id: ID!
name: String
...
}
then your mutation is something like this, where the input type becomes an object Cypher parameter:
createAccess(user: WorkstationUserInput, ...): WorkstationUser @cypher(statement:
"""
MATCH (from:WorkstationUser {id: $user.id})
....
"""
All the sessions of the conference are now available online