Search code examples
rneo4jgraphqlapollo

How to query a Neo4j relationship in R?


I have a Project node connected to a Skill node by a relationship "IN_NEED_OF". I am using an R-Shiny app with the Neo4j GraphQL library to pull the data I need. Currently, this code works:

execute_query = function(query) {
    result <- conn$exec(Query$new()$query('link', query)$link)
    flat_result <- result %>% fromJSON(flatten = F)
    # print(flat_result)
    result.df <- as.data.frame(flat_result[[1]])
    # print(result.df)
    output$table <- DT::renderDataTable({result.df}, rownames = TRUE, filter = 'top', selection = 'single', extensions = 'Buttons')
}

# Run a query
execute_query('
query SampleQuery {
Project{
    name
    description
}
}
')

However, I need the skills that are connected by "IN_NEED_OF". I have tried these blocks and have received errors for each one:

# Run a query
execute_query('
query SampleQuery {
Project{
    name
    description
    challenges: [Skill]
    @cypher(
        statement: """
        MATCH (p:Project)-[:IN_NEED_OF]->(s:Skill)
        RETURN s
        """
}
}
')

This fails because the challenges piece shouldn't be in the actual query but it the schema.

execute_query('
type Project{
    name: String!
    description: String!
    challenges(limit: Int = 10): [Skill]
    @relationship(type: "IN_NEED_OF", direction: OUT)
}
type Skill{
    name
}
query SampleQuery {
Project{
    name
    description
    challenges{
        name
    }

}
}
')

This fails because

Error : 2.5-7.5: schema support disabled

I have tried several variations of these two code blocks but I can't figure out if my problem is in R, the execute_query and function, or in the way I am using GraphQL.

(The server is an Apollo with a GraphQL API from the Neo4j GraphQL library.)


Solution

  • I figured it out! I am using a template and didn't realize that my schema was being inferred from Neo4j, so I wasn't allowed to change it. I changed my index.js to include a console print out of my schema and found the name of the relationship I needed.

        const inferAugmentedSchema = driver => {
      return inferSchema(driver).then(result => {
        console.log(result.typeDefs)
        return makeAugmentedSchema({
          typeDefs: result.typeDefs
        });
      });
    };
    

    I know a lot more of the template than I did yesterday, haha!