-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…5128) * Upgrade immer * Return sooner if predicates are empty * Fix bug when trying to delete a model instance that is not persisted * Support non-@model types * Generate datastore coverage report and RN integ test * Fix tslint error * Remove unit test case for onGetPost * Remove unused code * Rename instance initializer to initializeInstance * Rename SchemaType to SchemaNonModel * Rename types to nonModels in schema.js * Rename type to nonModel * Make nonModels optional in schema.js * Remove generic constraint from createTypeClass * Rename ModelOrTypeConstructorMap to TypeConstructorMap * Rename createModelAndTypeClassses to createTypeClasses * Rename createTypeClass to createNonModelClass
- Loading branch information
1 parent
0ddb6af
commit b884ea2
Showing
17 changed files
with
726 additions
and
175 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import { parse, print } from 'graphql'; | ||
import { SchemaNamespace } from '../src'; | ||
import { | ||
buildGraphQLOperation, | ||
buildSubscriptionGraphQLOperation, | ||
TransformerMutationType, | ||
} from '../src/sync/utils'; | ||
import { newSchema } from './schema'; | ||
|
||
const postSelectionSet = ` | ||
id | ||
title | ||
metadata { | ||
rating | ||
tags | ||
nested { | ||
aField | ||
} | ||
} | ||
_version | ||
_lastChangedAt | ||
_deleted | ||
reference { | ||
id | ||
_deleted | ||
} | ||
blog { | ||
id | ||
_deleted | ||
} | ||
`; | ||
|
||
describe('DataStore GraphQL generation', () => { | ||
test.each([ | ||
[ | ||
'LIST', | ||
/* GraphQL */ ` | ||
query operation( | ||
$limit: Int | ||
$nextToken: String | ||
$lastSync: AWSTimestamp | ||
) { | ||
syncPosts(limit: $limit, nextToken: $nextToken, lastSync: $lastSync) { | ||
items { | ||
${postSelectionSet} | ||
} | ||
nextToken | ||
startedAt | ||
} | ||
} | ||
`, | ||
], | ||
[ | ||
'CREATE', | ||
/* GraphQL */ ` | ||
mutation operation($input: CreatePostInput!) { | ||
createPost(input: $input) { | ||
${postSelectionSet} | ||
} | ||
} | ||
`, | ||
], | ||
[ | ||
'UPDATE', | ||
/* GraphQL */ ` | ||
mutation operation( | ||
$input: UpdatePostInput! | ||
$condition: ModelPostConditionInput | ||
) { | ||
updatePost(input: $input, condition: $condition) { | ||
${postSelectionSet} | ||
} | ||
} | ||
`, | ||
], | ||
, | ||
[ | ||
'DELETE', | ||
/* GraphQL */ ` | ||
mutation operation( | ||
$input: DeletePostInput! | ||
$condition: ModelPostConditionInput | ||
) { | ||
deletePost(input: $input, condition: $condition) { | ||
${postSelectionSet} | ||
} | ||
} | ||
`, | ||
], | ||
, | ||
[ | ||
'GET', | ||
/* GraphQL */ ` | ||
query operation($id: ID!) { | ||
getPost(id: $id) { | ||
${postSelectionSet} | ||
} | ||
} | ||
`, | ||
], | ||
])( | ||
'%s - has full selection set including types, and inputs', | ||
(graphQLOpType, expectedGraphQL) => { | ||
const namespace = <SchemaNamespace>(<unknown>newSchema); | ||
|
||
const { | ||
models: { Post: postModelDefinition }, | ||
} = namespace; | ||
|
||
const [[, , query]] = buildGraphQLOperation( | ||
namespace, | ||
postModelDefinition, | ||
<any>graphQLOpType | ||
); | ||
|
||
expect(print(parse(query))).toStrictEqual(print(parse(expectedGraphQL))); | ||
} | ||
); | ||
|
||
test.each([ | ||
[ | ||
TransformerMutationType.CREATE, | ||
/* GraphQL */ ` | ||
subscription operation { | ||
onCreatePost { | ||
${postSelectionSet} | ||
} | ||
} | ||
`, | ||
], | ||
[ | ||
TransformerMutationType.UPDATE, | ||
/* GraphQL */ ` | ||
subscription operation { | ||
onUpdatePost { | ||
${postSelectionSet} | ||
} | ||
} | ||
`, | ||
], | ||
[ | ||
TransformerMutationType.DELETE, | ||
/* GraphQL */ ` | ||
subscription operation { | ||
onDeletePost { | ||
${postSelectionSet} | ||
} | ||
} | ||
`, | ||
], | ||
])( | ||
'Subscription (%s) - has full selection set including types, and inputs', | ||
(transformerMutationType, expectedGraphQL) => { | ||
const namespace = <SchemaNamespace>(<unknown>newSchema); | ||
|
||
const { | ||
models: { Post: postModelDefinition }, | ||
} = namespace; | ||
|
||
const [, , query] = buildSubscriptionGraphQLOperation( | ||
namespace, | ||
postModelDefinition, | ||
<any>transformerMutationType, | ||
false, | ||
'' | ||
); | ||
|
||
expect(print(parse(query))).toStrictEqual(print(parse(expectedGraphQL))); | ||
} | ||
); | ||
}); |
Oops, something went wrong.