Skip to content

Commit

Permalink
test(graphql-default-value-transformer): @default is not to be used o…
Browse files Browse the repository at this point in the history
…n primaryKey fields
  • Loading branch information
p5quared committed Sep 12, 2024
1 parent 358df48 commit 5db3514
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,38 @@ describe('DefaultValueModelTransformer:', () => {
).toThrow('Default value "text" is not a valid AWSIPAddress.');
});

it('throws if @default is used on an implicit primaryKey', () => {
const schema = `
type Test @model {
id: ID! @default(value: "ID: 80361")
stringValue: String!
}
`;

expect(() =>
testTransform({
schema,
transformers: [new ModelTransformer(), new DefaultValueTransformer()],
}),
).toThrow('The @default directive may not be applied to primaryKey fields.');
});

it('throws if @default is used on an explicit primaryKey', () => {
const schema = `
type Test @model {
id: ID! @default(value: "ID: 80361") @primaryKey
stringValue: String!
}
`;

expect(() =>
testTransform({
schema,
transformers: [new ModelTransformer(), new DefaultValueTransformer(), new PrimaryKeyTransformer()],
}),
).toThrow('The @default directive may not be applied to primaryKey fields.');
});

it('should validate enum values', async () => {
const inputSchema = `
type Post @model {
Expand Down

0 comments on commit 5db3514

Please sign in to comment.