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(graphql-model-transformer): fixed @model scalar types model filter input generation #7892

Closed
wants to merge 105 commits into from
Closed
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
39a0e5c
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
acd11b3
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
d5107fc
fix(graphql-model-transformer): added call for validateModelSchema an…
lazpavel Aug 4, 2021
f9064cd
Merge branch 'master' into graphql-transformer-multiple-models
lazpavel Aug 4, 2021
2b4f56e
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
5de2dff
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
c37d83e
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
f84e74c
test(amplify-e2e-tests): fix casing for api name (#7885)
SwaySway Aug 4, 2021
83976df
fix: fiux e2e tests by passing categoryName for the resource (#7886)
akshbhu Aug 4, 2021
7d5023b
fix(container-hosting): e2e test fix (#7889)
sundersc Aug 4, 2021
4067727
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
d66091e
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
6065112
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 8, 2021
63ee64f
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
5c71ddf
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
b9bb61e
fix(container-hosting): e2e test fix (#7889)
sundersc Aug 4, 2021
e752290
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
7faf3cf
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
f794c8d
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
e5726ea
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
b8c77ff
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
2209b7c
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
411c651
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
282b666
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
21a6fdd
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
7caa853
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
8a70556
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
0e9d09c
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
1ad96d7
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
c20ea99
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
671cced
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
b047db7
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
0a3ae14
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
dd20a9a
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
0f33e25
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
1e29af4
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
eeef122
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
e3031ff
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
aa41616
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
faffbd2
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
feb1b96
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
791f507
chore(graphql-model-transformer): added validateModelSchema to unit test
lazpavel Aug 9, 2021
fbfc90a
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
b58e4c8
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
113f72b
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
5ac1eac
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
59e0826
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
d77af68
Merge branch 'graphql-transformer-multiple-models' of github.com:lazp…
lazpavel Aug 9, 2021
0e8651f
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 9, 2021
05cbc65
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 9, 2021
15b0ae1
chore(graphql-model-transformer): fixed filter naming and @index test
lazpavel Aug 9, 2021
f38ff6a
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
786a758
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
b192fd0
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
06a32fc
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
58846ce
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
b102f28
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 9, 2021
3988010
chore(graphql-model-transformer): fixed filter naming and @index test
lazpavel Aug 9, 2021
856420b
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 9, 2021
ecd656e
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 9, 2021
41e9cf4
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 9, 2021
b23ff2f
fix(container-hosting): e2e test fix (#7889)
sundersc Aug 4, 2021
7b7c6d0
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
b1dd2c6
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
aed6076
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
9ef7877
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
5049a69
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
9c16a96
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
a4bf532
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
40929bb
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
3c2546f
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
00432d8
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
067a16f
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
043cd9e
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
eb1cebe
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
84a1ce0
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
83c7319
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
7daec4e
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
b88335a
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
69a4215
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
72af7ef
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
8b64642
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
a752579
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
296c28a
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
a083827
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
2c99b27
chore(graphql-model-transformer): added validateModelSchema to unit test
lazpavel Aug 9, 2021
cc17930
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
0159d5d
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
6292b92
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
0a6a71c
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
36669d2
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
3f25444
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
f44cf80
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
26ce24c
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
ba5a23e
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
899a95d
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
ac8ea62
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 9, 2021
7e753a3
fix(graphql-model-transformer): implemented support for nested non mo…
lazpavel Aug 4, 2021
73e7ceb
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
fb6ed60
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
0cf207d
fix(graphql-model-transformer): fixed input type field generation for…
lazpavel Aug 4, 2021
5608605
fix(graphql-model-transformer): fixed @model scalar types model filte…
lazpavel Aug 4, 2021
969d1b6
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 9, 2021
35b4abf
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 16, 2021
95eae23
chore(graphql-model-transformer): fixed merge conflicts
lazpavel Aug 16, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('amplify add hosting - container', () => {
await initJSProjectWithProfile(projRoot, {});
await amplifyConfigureProject({
cwd: projRoot,
enableContainers: true
enableContainers: true,
});
// TODO: This needs attention. Need to force circle ci to run this test in us-east-1
// await addDevContainerHosting(projRoot);
Expand Down
14 changes: 7 additions & 7 deletions packages/amplify-graphql-index-transformer/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ function generateFilterInputs(config: IndexDirectiveConfiguration, ctx: Transfor
function makeModelXFilterInputObject(config: IndexDirectiveConfiguration, ctx: TransformerContextProvider): InputObjectTypeDefinitionNode {
const { object } = config;
const name = ModelResourceIDs.ModelFilterInputTypeName(object.name.value);
const supportsConditions = true;
const fields = object
.fields!.filter((field: FieldDefinitionNode) => {
const fieldType = ctx.output.getType(getBaseType(field.type));
Expand All @@ -389,13 +388,14 @@ function makeModelXFilterInputObject(config: IndexDirectiveConfiguration, ctx: T
})
.map((field: FieldDefinitionNode) => {
const baseType = getBaseType(field.type);
const fieldType = ctx.output.getType(baseType);
const isList = isListType(field.type);
const isEnumType = fieldType && fieldType.kind === Kind.ENUM_TYPE_DEFINITION;
const filterTypeName =
isEnumType && isList
? ModelResourceIDs.ModelFilterListInputTypeName(baseType, !supportsConditions)
: ModelResourceIDs.ModelScalarFilterInputTypeName(baseType, !supportsConditions);
let filterTypeName = baseType;

if (isScalar(field.type) || isList) {
filterTypeName = isList
? ModelResourceIDs.ModelFilterListInputTypeName(baseType, true)
: ModelResourceIDs.ModelScalarFilterInputTypeName(baseType, true);
}

return {
kind: Kind.INPUT_VALUE_DEFINITION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getFieldOnObjectType,
getInputType,
getObjectType,
verifyInputCount,
verifyMatchingTypes,
} from './test-utils/helpers';

Expand Down Expand Up @@ -412,6 +413,63 @@ describe('ModelTransformer: ', () => {
expect(result.pipelineFunctions['Mutation.createPost.req.vtl']).toMatchSnapshot();
});

it('support schema with multiple model directives', () => {
const validSchema = `
type Post @model {
id: ID!
title: String!
createdAt: String
updatedAt: String
}

type User @model {
id: ID!
name: String!

}
`;
const transformer = new GraphQLTransform({
transformers: [new ModelTransformer()],
featureFlags,
});

const out = transformer.transform(validSchema);
expect(out).toBeDefined();

const definition = out.schema;
expect(definition).toBeDefined();
const parsed = parse(definition);
validateModelSchema(parsed);

const queryType = getObjectType(parsed, 'Query');
expect(queryType).toBeDefined();
expectFields(queryType!, ['listPosts']);
expectFields(queryType!, ['listUsers']);

const stringInputType = getInputType(parsed, 'ModelStringFilterInput');
expect(stringInputType).toBeDefined();
const booleanInputType = getInputType(parsed, 'ModelBooleanFilterInput');
expect(booleanInputType).toBeDefined();
const intInputType = getInputType(parsed, 'ModelIntFilterInput');
expect(intInputType).toBeDefined();
const floatInputType = getInputType(parsed, 'ModelFloatFilterInput');
expect(floatInputType).toBeDefined();
const idInputType = getInputType(parsed, 'ModelIDFilterInput');
expect(idInputType).toBeDefined();
const postInputType = getInputType(parsed, 'ModelPostFilterInput');
expect(postInputType).toBeDefined();
const userInputType = getInputType(parsed, 'ModelUserFilterInput');
expect(userInputType).toBeDefined();

expect(verifyInputCount(parsed, 'ModelStringFilterInput', 1)).toBeTruthy();
expect(verifyInputCount(parsed, 'ModelBooleanFilterInput', 1)).toBeTruthy();
expect(verifyInputCount(parsed, 'ModelIntFilterInput', 1)).toBeTruthy();
expect(verifyInputCount(parsed, 'ModelFloatFilterInput', 1)).toBeTruthy();
expect(verifyInputCount(parsed, 'ModelIDFilterInput', 1)).toBeTruthy();
expect(verifyInputCount(parsed, 'ModelPostFilterInput', 1)).toBeTruthy();
expect(verifyInputCount(parsed, 'ModelUserFilterInput', 1)).toBeTruthy();
});

it('should support enum as a field', () => {
const validSchema = `
enum Status { DELIVERED IN_TRANSIT PENDING UNKNOWN }
Expand All @@ -438,4 +496,60 @@ describe('ModelTransformer: ', () => {
const updateTestInput = getInputType(parsed, 'CreateTestInput');
expectFieldsOnInputType(updateTestInput!, ['status', 'lastStatus']);
});

it('should support non-model types and enums', () => {
const validSchema = `
type Post @model {
id: ID!
title: String!
createdAt: String
updatedAt: String
metadata: [PostMetadata!]!
appearsIn: [Episode]!
}
type PostMetadata {
tags: Tag
}
type Tag {
published: Boolean
metadata: PostMetadata
}
enum Episode {
NEWHOPE
EMPIRE
JEDI
}
`;
const transformer = new GraphQLTransform({
transformers: [new ModelTransformer()],
featureFlags,
});
const out = transformer.transform(validSchema);
expect(out).toBeDefined();

const definition = out.schema;
expect(definition).toBeDefined();
const parsed = parse(definition);
validateModelSchema(parsed);

const postMetaDataInputType = getInputType(parsed, 'PostMetadataInput');
expect(postMetaDataInputType).toBeDefined();
const tagInputType = getInputType(parsed, 'TagInput');
expect(tagInputType).toBeDefined();
expectFieldsOnInputType(tagInputType!, ['metadata']);
const createPostInputType = getInputType(parsed, 'CreatePostInput');
expectFieldsOnInputType(createPostInputType!, ['metadata', 'appearsIn']);
const updatePostInputType = getInputType(parsed, 'UpdatePostInput');
expectFieldsOnInputType(updatePostInputType!, ['metadata', 'appearsIn']);

const postModelObject = getObjectType(parsed, 'Post');
const postMetaDataInputField = getFieldOnInputType(createPostInputType!, 'metadata');
const postMetaDataField = getFieldOnObjectType(postModelObject!, 'metadata');
// this checks that the non-model type was properly "unwrapped", renamed, and "rewrapped"
// in the generated CreatePostInput type - its types should be the same as in the Post @model type
verifyMatchingTypes(postMetaDataInputField.type, postMetaDataField.type);

expect(verifyInputCount(parsed, 'PostMetadataInput', 1)).toBeTruthy();
expect(verifyInputCount(parsed, 'TagInput', 1)).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ export class ModelTransformer extends TransformerModelBase implements Transforme
if (!ctx.output.getType(name)) {
const inputObj = InputObjectDefinitionWrapper.fromObject(name, def, ctx.inputDocument);
ctx.output.addInput(inputObj.serialize());
this.createNonModelInputs(ctx, def);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
makeField,
makeNamedType,
makeValueNode,
ModelResourceIDs,
toPascalCase,
} from 'graphql-transformer-common';
import {
Expand Down Expand Up @@ -52,11 +53,14 @@ export const makeConditionFilterInput = (
for (let field of wrappedObject.fields) {
const fieldType = ctx.output.getType(field.getTypeName());
const isEnumType = fieldType && fieldType.kind === 'EnumTypeDefinition';
if (field.isScalar() || isEnumType) {
const fieldTypeName = field.getTypeName();
const nameOverride = DEFAULT_SCALARS[fieldTypeName] || fieldTypeName;
const conditionTypeName = isEnumType && field.isList() ? `Model${nameOverride}ListInput` : `Model${nameOverride}Input`;
const inputField = InputFieldWrapper.create(field.name, conditionTypeName, true);
if (field.isScalar() || field.isList()) {
const conditionTypeName = field.isList()
? ModelResourceIDs.ModelFilterListInputTypeName(field.getTypeName(), true)
: ModelResourceIDs.ModelFilterScalarInputTypeName(field.getTypeName(), true);
const inputField = InputFieldWrapper.create(field.name, conditionTypeName, true, field.isList());
input.addField(inputField);
} else if (isEnumType) {
const inputField = InputFieldWrapper.create(field.name, field.getTypeName(), true, field.isList());
input.addField(inputField);
}
}
Expand All @@ -76,7 +80,7 @@ export const makeConditionFilterInput = (

export const addModelConditionInputs = (ctx: TransformerTransformSchemaStepContextProvider): void => {
const conditionsInput: TypeDefinitionNode[] = ['String', 'Int', 'Float', 'Boolean', 'ID'].map(scalarName =>
makeModelScalarFilterInputObject(scalarName, true),
makeModelScalarFilterInputObject(scalarName, false),
);
conditionsInput.push(makeAttributeTypeEnum());
conditionsInput.push(makeSizeInputType());
Expand All @@ -90,7 +94,7 @@ export const addModelConditionInputs = (ctx: TransformerTransformSchemaStepConte

/**
*
* @param typeName Name of the scarlar type
* @param typeName Name of the scalar type
* @param includeFilter add filter suffix to input
*/
export function generateModelScalarFilterInputName(typeName: string, includeFilter: boolean): string {
Expand All @@ -100,6 +104,7 @@ export function generateModelScalarFilterInputName(typeName: string, includeFilt
}
return `Model${typeName}${includeFilter ? 'Filter' : ''}Input`;
}

export const createEnumModelFilters = (
ctx: TransformerTransformSchemaStepContextProvider,
type: ObjectTypeDefinitionNode,
Expand Down
Loading