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

content client fixes #655

Merged
merged 5 commits into from
Dec 18, 2023
Merged
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
4 changes: 2 additions & 2 deletions build/api/client-content.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export namespace ContentClientInput {
};
// (undocumented)
export type CreateDataInput<TEntity extends EntityTypeLike> = {
readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key]['tsType'];
readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key];
} & {
readonly [key in keyof TEntity['hasMany']]?: CreateManyRelationInput<TEntity['hasMany'][key]>;
} & {
Expand Down Expand Up @@ -141,7 +141,7 @@ export namespace ContentClientInput {
export type UniqueWhere<TEntity extends EntityTypeLike> = TEntity['unique'];
// (undocumented)
export type UpdateDataInput<TEntity extends EntityTypeLike> = {
readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key]['tsType'];
readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key];
} & {
readonly [key in keyof TEntity['hasMany']]?: UpdateManyRelationInput<TEntity['hasMany'][key]>;
} & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ContemberClientNames: SchemaNames = ` + JSON.stringify(nameSchema,

const indexCode = `
import { ContemberClientNames } from './names'
import { ContemberClientSchema } from './entities'
import type { ContemberClientSchema } from './entities'
import { ContentQueryBuilder, TypedContentQueryBuilder, TypedEntitySelection } from '@contember/client-content'
export * from './names'
export * from './enums'
Expand Down
8 changes: 6 additions & 2 deletions packages/client-content/src/ContentQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ export class ContentQueryBuilder {
const transactionArgs = createTypedArgs({ options }, {
options: 'MutationTransactionOptions',
})
return new ContentOperation<TransactionResult<any>, 'mutation'>('mutation', 'transaction', transactionArgs, combined.selection, ({ ok, errorMessage, errors, validation, ...data }) => {
const items = [
...this.createMutationSelection('transaction'),
...combined.selection,
]
return new ContentOperation<TransactionResult<any>, 'mutation'>('mutation', 'transaction', transactionArgs, items, ({ ok, errorMessage, errors, validation, ...data }) => {
return {
ok,
errorMessage,
Expand All @@ -158,7 +162,7 @@ export class ContentQueryBuilder {
})
}

private createMutationSelection(operation: 'create' | 'update' | 'delete' | 'upsert', selection?: GraphQlSelectionSet): GraphQlSelectionSet {
private createMutationSelection(operation: 'create' | 'update' | 'delete' | 'upsert' | 'transaction', selection?: GraphQlSelectionSet): GraphQlSelectionSet {
const items: GraphQlSelectionSet = [
new GraphQlField(null, 'ok'),
new GraphQlField(null, 'errorMessage'),
Expand Down
4 changes: 2 additions & 2 deletions packages/client-content/src/types/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export namespace ContentClientInput {

export type CreateDataInput<TEntity extends EntityTypeLike> =
& {
readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key]['tsType']
readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key]
}
& {
readonly [key in keyof TEntity['hasMany']]?: CreateManyRelationInput<TEntity['hasMany'][key]>
Expand All @@ -82,7 +82,7 @@ export namespace ContentClientInput {

export type UpdateDataInput<TEntity extends EntityTypeLike> =
& {
readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key]['tsType']
readonly [key in keyof TEntity['columns']]?: TEntity['columns'][key]
}
& {
readonly [key in keyof TEntity['hasMany']]?: UpdateManyRelationInput<TEntity['hasMany'][key]>
Expand Down
163 changes: 122 additions & 41 deletions packages/client-content/tests/cases/unit/mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ describe('mutations in trx', () => {
expect(calls[0].query).toMatchInlineSnapshot(`
"mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_AuthorCreateInput_1: AuthorCreateInput!) {
mut: transaction(options: $options_MutationTransactionOptions_0) {
ok
errorMessage
errors {
... MutationError
}
validation {
... ValidationResult
}
mut: createAuthor(data: $data_AuthorCreateInput_1) {
ok
errorMessage
Expand Down Expand Up @@ -101,6 +109,14 @@ describe('mutations in trx', () => {
expect(calls[0].query).toMatchInlineSnapshot(`
"mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_AuthorCreateInput_1: AuthorCreateInput!) {
mut: transaction(options: $options_MutationTransactionOptions_0) {
ok
errorMessage
errors {
... MutationError
}
validation {
... ValidationResult
}
mut: createAuthor(data: $data_AuthorCreateInput_1) {
ok
errorMessage
Expand Down Expand Up @@ -179,6 +195,14 @@ describe('mutations in trx', () => {
expect(calls[0].query).toMatchInlineSnapshot(`
"mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $by_AuthorUniqueWhere_1: AuthorUniqueWhere!, $data_AuthorUpdateInput_2: AuthorUpdateInput!) {
mut: transaction(options: $options_MutationTransactionOptions_0) {
ok
errorMessage
errors {
... MutationError
}
validation {
... ValidationResult
}
mut: updateAuthor(by: $by_AuthorUniqueWhere_1, data: $data_AuthorUpdateInput_2) {
ok
errorMessage
Expand Down Expand Up @@ -253,6 +277,14 @@ describe('mutations in trx', () => {
expect(calls[0].query).toMatchInlineSnapshot(`
"mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $by_AuthorUniqueWhere_1: AuthorUniqueWhere!) {
mut: transaction(options: $options_MutationTransactionOptions_0) {
ok
errorMessage
errors {
... MutationError
}
validation {
... ValidationResult
}
mut: deleteAuthor(by: $by_AuthorUniqueWhere_1) {
ok
errorMessage
Expand All @@ -275,6 +307,23 @@ describe('mutations in trx', () => {
message
type
}
fragment ValidationResult on _ValidationResult {
valid
errors {
path {
... on _FieldPathFragment {
field
}
... on _IndexPathFragment {
index
alias
}
}
message {
text
}
}
}
"
`)
expect(calls[0].variables).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -309,52 +358,60 @@ describe('mutations in trx', () => {
})))
expect(calls).toHaveLength(1)
expect(calls[0].query).toMatchInlineSnapshot(`
"mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $by_AuthorUniqueWhere_1: AuthorUniqueWhere!, $create_AuthorCreateInput_2: AuthorCreateInput!, $update_AuthorUpdateInput_3: AuthorUpdateInput!) {
mut: transaction(options: $options_MutationTransactionOptions_0) {
mut: upsertAuthor(by: $by_AuthorUniqueWhere_1, create: $create_AuthorCreateInput_2, update: $update_AuthorUpdateInput_3) {
ok
errorMessage
errors {
... MutationError
}
validation {
... ValidationResult
}
}
}
"mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $by_AuthorUniqueWhere_1: AuthorUniqueWhere!, $create_AuthorCreateInput_2: AuthorCreateInput!, $update_AuthorUpdateInput_3: AuthorUpdateInput!) {
mut: transaction(options: $options_MutationTransactionOptions_0) {
ok
errorMessage
errors {
... MutationError
}
fragment MutationError on _MutationError {
paths {
... on _FieldPathFragment {
field
}
... on _IndexPathFragment {
index
alias
}
}
message
type
validation {
... ValidationResult
}
fragment ValidationResult on _ValidationResult {
valid
mut: upsertAuthor(by: $by_AuthorUniqueWhere_1, create: $create_AuthorCreateInput_2, update: $update_AuthorUpdateInput_3) {
ok
errorMessage
errors {
path {
... on _FieldPathFragment {
field
}
... on _IndexPathFragment {
index
alias
}
}
message {
text
}
... MutationError
}
validation {
... ValidationResult
}
}
"
`)
}
}
fragment MutationError on _MutationError {
paths {
... on _FieldPathFragment {
field
}
... on _IndexPathFragment {
index
alias
}
}
message
type
}
fragment ValidationResult on _ValidationResult {
valid
errors {
path {
... on _FieldPathFragment {
field
}
... on _IndexPathFragment {
index
alias
}
}
message {
text
}
}
}
"
`)
expect(calls[0].variables).toMatchInlineSnapshot(`
{
"by_AuthorUniqueWhere_1": {
Expand Down Expand Up @@ -407,6 +464,14 @@ describe('mutations in trx', () => {
expect(calls[0].query).toMatchInlineSnapshot(`
"mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_AuthorCreateInput_1: AuthorCreateInput!, $data_AuthorCreateInput_2: AuthorCreateInput!) {
mut: transaction(options: $options_MutationTransactionOptions_0) {
ok
errorMessage
errors {
... MutationError
}
validation {
... ValidationResult
}
mut_0: createAuthor(data: $data_AuthorCreateInput_1) {
ok
errorMessage
Expand Down Expand Up @@ -508,6 +573,14 @@ describe('mutations in trx', () => {
expect(calls[0].query).toMatchInlineSnapshot(`
"mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_AuthorCreateInput_1: AuthorCreateInput!, $data_PostCreateInput_2: PostCreateInput!) {
mut: transaction(options: $options_MutationTransactionOptions_0) {
ok
errorMessage
errors {
... MutationError
}
validation {
... ValidationResult
}
createAuthor(data: $data_AuthorCreateInput_1) {
ok
errorMessage
Expand Down Expand Up @@ -613,6 +686,14 @@ describe('mutations in trx', () => {
expect(calls[0].query).toMatchInlineSnapshot(`
"mutation($options_MutationTransactionOptions_0: MutationTransactionOptions, $data_PostCreateInput_1: PostCreateInput!, $by_PostUniqueWhere_2: PostUniqueWhere!) {
mut: transaction(options: $options_MutationTransactionOptions_0) {
ok
errorMessage
errors {
... MutationError
}
validation {
... ValidationResult
}
createPost(data: $data_PostCreateInput_1) {
ok
errorMessage
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2798,7 +2798,7 @@ __metadata:
"@contember/schema-utils": ^1.3.6
"@types/node": ^18
bin:
contember-client-generator: ./dist/production/generate.js
contember-client-generator: ./dist/production/generate.cjs
languageName: unknown
linkType: soft

Expand Down
Loading