cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Querying relationship properties in GraphQL

pingelsan
Node Clone

Hi,
I'm trying to query relationship properties via GraphQL.
As was mentioned here:
https://grandstack.io/docs/graphql-relationship-types.html#relationships-with-properties ,
I built a relationship type to include in my query.
The underlying graph is quite simple: There are skill profiles (of users) that are defined by their relationships to single (atomic) skills. This relationship has a 'value' (or 'key figure') that describes how proficient someone is in a that skill.
The relevant parts of the schema look like this:

type Skillprofile {
   _id: Long!
   name: String!
   has_skill: [Skill] @relation(name: "HAS_SKILL", direction: "OUT")
   skillfeature: [Skillfeature]
   persons: [Person] @relation(name: "HAS_SKILLS_REPORTED_IN", direction: "IN")
}

type Skillfeature @relation(name: "HAS_SKILL") {
  from: Skillprofile
  to: Skill
  value: Float
}

However, when I ask for the relationship in GraphQL, I get an error:

          "code": "GRAPHQL_VALIDATION_FAILED",
          "exception": {
            "stacktrace": [
              "GraphQLError: Cannot query field \"from\" on type \"_SkillprofileSkillfeature\".",

I'd expect that I can simply query the 'from' and 'to' fields of the relationship type, just like that 'value'. Which, BTW, is returned properly.

Thanks for any input,
best regards,
Christoph

8 REPLIES 8

Try

type Skill {
    id: ID!
    name: String!
    persons: [Person] @relation(name: "HAS_SKILL", direction: "IN")
} 

type Person {
    id: ID!
    name: String!
    skills: [Skill] @relation(name: "HAS_SKILL", direction: "OUT")
}

or try

type Skill {
    id: ID!
    name: String!
    persons: [Has_Skill]
} 

type Person {
    id: ID!
    name: String!
    skills: [Has_Skill]
}

type Has_Skill @relation(name: "HAS_SKILL") {
  from: Person
  to: Skill
  level: Float
}

look for in schema
mutation {
AddSkillPersons
}

Thank you, I'll give it a try!

best,
Christoph

Did anybody managed to read properties on a relationship using graphQL?

none of the above solution worked for me.

What I am trying is just to access a property like type from below
(User)-[:HAS_SKILL {type:"technical"}]->(Java)

any solutions here?
I wondering about this problem, too.

iuviene
Node Link

Based on @futuristnicole 's second solution as the GraphQL schema, the client side code should be able to query that with the following GraphQL query:

query {
   Person {
      name
      skills {
         level
         Skill {
             name
         }
      }
   }
}

Only other issue for your query, @dejavu1987, is I don't think you can use 'type' for a property of a relationship. It will just be ignored.

Funny, doing a web search, I came back to my own question. 🙂 I'll give the solution of iuviene a try.

In this example, is there a clean way to sort by skills level?