Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

How can I give graphQL context of current signed in user? #563

Open
dan-fein opened this issue Jan 2, 2021 · 2 comments
Open

How can I give graphQL context of current signed in user? #563

dan-fein opened this issue Jan 2, 2021 · 2 comments

Comments

@dan-fein
Copy link

dan-fein commented Jan 2, 2021

I have the below definition for a Thing and I can't seem to figure out how to get isFollowing to work as it's not clear how to pass custom variables to neo4j-graphql-js.

I thought I might be able to put them in my query e.g:

query get_thing {
Thing (id: "QEQXbK2Z6Ngp40TMOYKVx73XtEu2", uid: "ffe38a42-474f-4426-bc45-2453e19a4d83") {
id
isFollowing
}

but it doesn't seem like there's any way for the "uid" variable that I passed to make its way to the Type Definition here, to be used for the "isFollowing" cypher directive.

type Thing {
    id: String,
    name: String,
    description: String,
    image: String,
    followers: [User] @relation(name: "FOLLOWS", direction: "IN"),
    follower_count: Int @cypher(statement: """
        MATCH (u:User)-[:FOLLOWS]->(this)
        RETURN count(u)
    """),
    isFollowing: Boolean @cypher(statement: """
            MATCH (u:User {id: $cypherParams.currentUserId}),(this)
            RETURN EXISTS((u)-[:FOLLOWS]->(t))
        """),
}

I've seen the ability to add contextParams to an @cypher directive (here), but it's unclear how to inject information like that into a query such that it's even retrievable from "req".

Any thoughts on how to pass a currently signed in user's ID in a graphql query to neo4j-graphql-js?

Thank you in advance, and Happy New Year!

I'm

@dmoree
Copy link

dmoree commented Jan 4, 2021

I don't believe this is the appropriate venue for this question as I don't think this is an issue with this package, but what you are looking for is adding an object called cypherParams to the GraphQL context.

For further reading I would recommend the documentation for neo4j-graphql-js here:
https://grandstack.io/docs/neo4j-graphql-js-middleware-authorization/#cypher-parameters-from-context

You will have to refer to the documentation specific to your GraphQL server, but an example for Apollo Server is here:
https://www.apollographql.com/docs/apollo-server/security/authentication/#putting-user-info-on-the-context

@michaeldgraham
Copy link
Collaborator

#608

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants