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

Passing context to @cypher, scalar payload mutations, fixes #200

Merged
merged 16 commits into from
Feb 18, 2019
Merged

Passing context to @cypher, scalar payload mutations, fixes #200

merged 16 commits into from
Feb 18, 2019

Conversation

michaeldgraham
Copy link
Collaborator

@michaeldgraham michaeldgraham commented Feb 17, 2019

This PR introduces fixes and improvements to @cypher directive fields.

Passing context data to @cypher statements

Passing context values to @cypher directive statements is now supported via a dedicated cypherParams context object in an Apollo server setup (#187).

In the below example, currentUserId is provided in the cypherParams context object. It can then be accessed as a Cypher parameter in all @cypher directives (including custom queries and mutations).

const server = new ApolloServer({
  ...,
  context: ({ req }) => {
    return {
      driver,
      req,
      cypherParams: {
        currentUserId: req.user.id
      }
    };
  }
});
const typeDefs = `
  type User {
    name: String
    currentUserId: String @cypher(statement: """
      RETURN $cypherParams.currentUserId
    """)
  }
`;
Fixes
Tests
Handle @cypher field with String payload using cypherParams
Handle nested @cypher fields that use cypherParams
Handle @cypher query using cypherParams with String payload
Handle @cypher query using cypherParams with Object payload
Handle @cypher query with Boolean payload
Handle @cypher query with Int payload
Handle @cypher query with Float payload
Handle @cypher query with String list payload
Handle @cypher query with Int list payload
Handle @cypher query with Temporal payload
Handle @cypher mutation using cypherParams with String payload
Handle @cypher mutation using cypherParams with Object payload
Handle @cypher mutation with String list payload
Handle @cypher mutation with Temporal payload
Handle @cypher mutation with input type argument
Handle @cypher query with parameterized input type argument
Handle nested @cypher fields using parameterized arguments and cypherParams

upstream update
upstream merge
upstream merge
replaced getQuerySelections and getMutationSelections with getPayloadSelections because, for scalar payload mutations, getMutationSelections would return a selection set equal to the mutation's arguments
refactoring introduced isScalarSchemaType and schemaTypeField variables
includes some defensive branches from implementing support for scalar payload mutations
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants