Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix bug with missing arrays and requireds in custom operation args #552

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ninety-ravens-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/data-schema': patch
---

fix bug with missing arrays and requireds in custom operation arguments
258 changes: 258 additions & 0 deletions packages/data-schema/__tests__/ModelSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,261 @@ describe('Lambda resource access', () => {
]);
});
});

describe('custom operation argument inputs', () => {

it('when the argument is an array of custom type refs the input is an array refs', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testType: a.customType({
testField: a.string().required(),
}),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testType').array(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is a required custom type ref the input is a required ref', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testType: a.customType({
testField: a.string().required(),
}),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testType').required(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is a required array of custom type refs the input is a required array', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testType: a.customType({
testField: a.string().required(),
}),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testType').array().required(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is an array of required custom type refs the input is an array of required refs', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testType: a.customType({
testField: a.string().required(),
}),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testType').required().array(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is a required array of required custom type refs the input is a required array of required refs', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testType: a.customType({
testField: a.string().required(),
}),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testType').required().array().required(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is an array of enum the input is an array', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testEnum: a.enum(['test1', 'test2']),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testEnum').array(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is a required enum the input is required', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testEnum: a.enum(['test1', 'test2']),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testEnum').required(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is a required array of enum refs the input is a required array', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testEnum: a.enum(['test1', 'test2']),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testEnum').array().required(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is an array of required enum refs the input is a array of required refs', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testEnum: a.enum(['test1', 'test2']),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testEnum').required().array(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is a required array of required enum refs the input is a required array of required refs', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testEnum: a.enum(['test1', 'test2']),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testEnum').required().array().required(),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is a custom type with an array field the input types field is an array', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testType: a.customType({
testField: a.string().array(),
}),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testType'),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

it('when the argument is a custom type with a required field the input types field is required', () => {
const fn1 = defineFunctionStub({});

const schema = a
.schema({
testType: a.customType({
testField: a.string().required(),
}),

testMutation: a
.mutation()
.arguments({
testArgument: a.ref('testType'),
})
.returns(a.string())
.handler(a.handler.function(fn1))
})
.authorization((allow) => allow.owner());

expect(schema.transform().schema).toMatchSnapshot();
});

})
Loading