Skip to content
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
18 changes: 9 additions & 9 deletions src/__tests__/Client.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
client,
Field,
Mutation,
Query,
CombinedField,
import {
client,
Field,
Mutation,
Query,
CombinedField,
InlineFragment
} from '../../src';

Expand All @@ -28,14 +28,14 @@ const combinedQuery = new CombinedField()

const insertUserMutation = new Mutation('insert_users')
.addArgument('objects', '[users_insert_input!]!', {
name: "Yegor",
name: "Yegor",
rocket: "SomeRocket"
})
.addField('affected_rows')
.addField(new Field('returning', true)
.addFieldList([
'id',
'name',
'id',
'name',
'rocket',
// @ts-ignore
new InlineFragment('users').addField('timestamp')
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/CombinedField.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('combined fields are built', () => {
const combinedField = new CombinedField()
.add(firstQuery)
.add(secondQuery);

expect(combinedField.getFields().length).toBe(2);
})

Expand All @@ -19,7 +19,7 @@ describe('combined fields are built', () => {
const combinedField = new CombinedField()
.add(firstMutation)
.add(secondMutation);

expect(combinedField.getFields().length).toBe(2);
})

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/DataType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const anotherQuery = new Query('car')

const mutation = new Mutation('someMutation')
.addField('some')
.addField('other');
.addField('other');

const combinedRequest = new CombinedField()
.add(query)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('field is built', () => {
it('adds childs fields as lists', () => {
const field = new Field('some')
.addFieldList([
'one',
'one',
'two'
]);

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/InlineFragment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('inline fragment is built', () => {
const inlineFragment = new InlineFragment('optional')
.addField('firstThing')
.addField('secondThing');

expect(inlineFragment.children.length).toBe(2);
})
})
26 changes: 13 additions & 13 deletions src/builder/AbstractField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export abstract class AbstractField<
readonly name: Name;

readonly isArray?: ArrayExpected;

readonly tag: keyof FieldDescendantStore<any, any, any> = 'AbstractField';

alias = '';

children: Array<InlineFragment<any, any> | Field<any, any, any>> = [];
Expand Down Expand Up @@ -67,7 +67,7 @@ export abstract class AbstractField<
*/
setAlias<Alias extends string>(alias: Alias): HigherKindType<
this['tag'],
Alias,
Alias,
FieldReturnType,
ArrayExpected
> {
Expand All @@ -90,7 +90,7 @@ export abstract class AbstractField<
NewFieldName extends string,
NewFieldType extends any
>(
field: NewFieldName,
field: NewFieldName,
calculator: (result: FieldReturnType) => NewFieldType
): HigherKindType<
this['tag'],
Expand Down Expand Up @@ -127,22 +127,22 @@ export abstract class AbstractField<
field: NewFieldName,
isArray?: IsArray
): HigherKindType<
this['tag'],
this['tag'],
Name,
FieldReturnType & {
[k in NewFieldName]: IsArray extends true
? FetchedFieldItemType[]
: FetchedFieldItemType
},
ArrayExpected
>
>

// INLINE FRAGMENT
addField<NewField extends InlineFragment<any, any>>(
addField<NewField extends InlineFragment<any, any>>(
field: NewField
): HigherKindType<
this['tag'],
Name,
this['tag'],
Name,
FieldReturnType & Partial<NewField['resultTypeHolder']>
>;

Expand All @@ -152,11 +152,11 @@ export abstract class AbstractField<
>(
field: F
): HigherKindType<
this['tag'],
Name,
FieldReturnType & {
this['tag'],
Name,
FieldReturnType & {
[k in F['name']]: F extends Field<any, any, true>
? F['resultTypeHolder'][]
? F['resultTypeHolder'][]
: F['resultTypeHolder']
},
ArrayExpected
Expand Down
2 changes: 1 addition & 1 deletion src/builder/CombinedField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class CombinedField<ReturnType> {
type?: GraphQlRequestType;

resultTypeHolder?: ReturnType;

protected fields: AbstractField<any, any, any>[] = [];

add<Name extends string, FieldReturnType, IsArray extends boolean>(
Expand Down
4 changes: 2 additions & 2 deletions src/builder/Field.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import AbstractField from './AbstractField';

export class Field<
Name extends string,
FieldReturnType,
Name extends string,
FieldReturnType,
IsArray extends boolean = false
> extends AbstractField<Name, FieldReturnType, IsArray> {
readonly tag = 'Field';
Expand Down
2 changes: 1 addition & 1 deletion src/builder/InlineFragment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AbstractField from './AbstractField';

export class InlineFragment<
N extends string,
N extends string,
RT
> extends AbstractField<N, RT, false> {
readonly tag = 'InlineFragment';
Expand Down
4 changes: 2 additions & 2 deletions src/builder/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { GraphQlRequestType } from "../client/prepare-document";
import { IRequestable } from "./interface/IRequestable";

class Mutation<
Name extends string,
FieldReturnType,
Name extends string,
FieldReturnType,
IsArray extends boolean = false
> extends AbstractField<Name, FieldReturnType, IsArray> implements IRequestable {
readonly tag = 'Mutation';
Expand Down
4 changes: 2 additions & 2 deletions src/builder/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { GraphQlRequestType } from "../client/prepare-document";
import { IRequestable } from "./interface/IRequestable";

class Query<
Name extends string,
FieldReturnType,
Name extends string,
FieldReturnType,
IsArray extends boolean = false
> extends AbstractField<Name, FieldReturnType, IsArray> implements IRequestable {
readonly tag = 'Query';
Expand Down
4 changes: 2 additions & 2 deletions src/builder/hkt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type InlineFragment from './InlineFragment';
import type AbstractField from './AbstractField';

export interface FieldDescendantStore<
N extends string,
RT,
N extends string,
RT,
A extends boolean
> {
Query: Query<N, RT, A>,
Expand Down
2 changes: 1 addition & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Client {
}

deep(Object.freeze, parsedResponse);

return parsedResponse;
};

Expand Down
4 changes: 2 additions & 2 deletions src/client/prepare-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface GraphQLDocument {
}

export const prepareFieldString = (
rootField: AbstractField<any, any, any>,
rootField: AbstractField<any, any, any>,
accArgs: AccArgs = {}
): string => {
const {
Expand Down Expand Up @@ -50,7 +50,7 @@ export const prepareFieldString = (
};

export const prepareRequest = (
fields: AbstractField<any, any, any>[],
fields: AbstractField<any, any, any>[],
type: GraphQlRequestType
): GraphQLDocument => {
const fieldsArray = Array.isArray(fields) ? fields : [fields];
Expand Down