forked from graphql-nexus/nexus-plugin-prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: forward nexus plugins into t.model and t.crud (graphql-nexus#687)
- Loading branch information
Showing
13 changed files
with
272 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`forwards plugins to t.crud 1`] = `[Error: Not authorized: {"response":{"data":null,"errors":[{"message":"Not authorized","locations":[{"line":2,"column":7}],"path":["users"]}],"status":200},"request":{"query":"{\\n users {\\n id\\n }\\n }"}}]`; | ||
|
||
exports[`forwards plugins to t.model 1`] = `[Error: Not authorized: {"response":{"data":null,"errors":[{"message":"Not authorized","locations":[{"line":3,"column":9}],"path":["users",0,"id"]}],"status":200},"request":{"query":"{\\n users {\\n id\\n }\\n }"}}]`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { objectType, fieldAuthorizePlugin } from '@nexus/schema' | ||
import { createRuntimeTestContext } from '../__client-test-context' | ||
|
||
let ctx = createRuntimeTestContext() | ||
|
||
it('forwards plugins to t.model', async () => { | ||
const datamodel = ` | ||
model User { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
} | ||
` | ||
const User = objectType({ | ||
name: 'User', | ||
definition(t: any) { | ||
t.model.id({ | ||
authorize() { | ||
return new Error('nope') | ||
}, | ||
}) | ||
}, | ||
}) | ||
|
||
const Query = objectType({ | ||
name: 'Query', | ||
definition(t: any) { | ||
t.crud.users() | ||
}, | ||
}) | ||
|
||
const { graphqlClient, dbClient } = await ctx.getContext({ | ||
datamodel, | ||
types: [Query, User], | ||
plugins: [fieldAuthorizePlugin()], | ||
}) | ||
|
||
await dbClient.user.create({ | ||
data: { | ||
name: 'Foo', | ||
}, | ||
}) | ||
|
||
try { | ||
await graphqlClient.request(`{ | ||
users { | ||
id | ||
} | ||
}`) | ||
} catch (e) { | ||
expect(e).toMatchSnapshot() | ||
} | ||
}) | ||
|
||
it('forwards plugins to t.crud', async () => { | ||
const datamodel = ` | ||
model User { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
} | ||
` | ||
const User = objectType({ | ||
name: 'User', | ||
definition(t: any) { | ||
t.model.id() | ||
}, | ||
}) | ||
|
||
const Query = objectType({ | ||
name: 'Query', | ||
definition(t: any) { | ||
t.crud.users({ | ||
authorize() { | ||
return new Error('nope') | ||
}, | ||
}) | ||
}, | ||
}) | ||
|
||
const { graphqlClient, dbClient } = await ctx.getContext({ | ||
datamodel, | ||
types: [Query, User], | ||
plugins: [fieldAuthorizePlugin()], | ||
}) | ||
|
||
await dbClient.user.create({ | ||
data: { | ||
name: 'Foo', | ||
}, | ||
}) | ||
|
||
try { | ||
await graphqlClient.request(`{ | ||
users { | ||
id | ||
} | ||
}`) | ||
} catch (e) { | ||
expect(e).toMatchSnapshot() | ||
} | ||
}) |
Oops, something went wrong.