Skip to content

Commit

Permalink
Fix #2294
Browse files Browse the repository at this point in the history
Ideally we would not have this inconsistent edge case that we filter
through the user type. Much better would be a graphql query like:

```graphql
{
  User(filter: { primary_email: { email: "something@example.org" } }) {
    id
    name
    slug
  }
}
```
  • Loading branch information
roschaefer committed Nov 19, 2019
1 parent c3d8cb6 commit b0d20ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 1 addition & 3 deletions backend/src/middleware/permissionsMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const noEmailFilter = rule({
const publicRegistration = rule()(() => !!CONFIG.PUBLIC_REGISTRATION)

// Permissions
const permissions = shield(
export default shield(
{
Query: {
'*': deny,
Expand Down Expand Up @@ -176,5 +176,3 @@ const permissions = shield(
fallbackRule: allow,
},
)

export default permissions
20 changes: 16 additions & 4 deletions backend/src/schema/resolvers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,22 @@ export default {
User: async (object, args, context, resolveInfo) => {
const { email } = args
if (email) {
const e = await instance.first('EmailAddress', { email })
let user = e.get('belongsTo')
user = await user.toJson()
return [user.node]
let session
try {
session = context.driver.session()
const readTxResult = await session.readTransaction(txc => {
const result = txc.run(
`
MATCH (user:User)-[:PRIMARY_EMAIL]->(e:EmailAddress {email: $args.email})
RETURN user`,
{ args },
)
return result
})
return readTxResult.records.map(r => r.get('user').properties)
} finally {
session.close()
}
}
return neo4jgraphql(object, args, context, resolveInfo)
},
Expand Down
15 changes: 15 additions & 0 deletions backend/src/schema/resolvers/users.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ describe('User', () => {
data: { User: [{ name: 'Johnny' }] },
})
})

it('non-existing email address, issue #2294', async () => {
// see: https://github.com/Human-Connection/Human-Connection/issues/2294
await expect(
query({
query: userQuery,
variables: {
email: 'this-email-does-not-exist@example.org',
},
}),
).resolves.toMatchObject({
data: { User: [] },
errors: undefined,
})
})
})
})
})
Expand Down

0 comments on commit b0d20ed

Please sign in to comment.