Skip to content

Commit

Permalink
minor fixes (#212)
Browse files Browse the repository at this point in the history
* fix getFields with nullable objects

* fix importsNotUsedAsValues error on generated schema

* allow set core "resolved" defaults
  • Loading branch information
PabloSzx committed May 19, 2021
1 parent 3e755d4 commit 422eb9a
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-mayflies-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gqless': patch
---

allow set core "resolved" defaults
5 changes: 5 additions & 0 deletions .changeset/happy-pets-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gqless/cli': patch
---

fix importsNotUsedAsValues error on generated schema
5 changes: 5 additions & 0 deletions .changeset/old-humans-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'gqless': patch
---

hotfix nullable getFields
6 changes: 2 additions & 4 deletions packages/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,13 @@ export const generatedSchema = {${Object.entries(generatedSchema).reduceRight(
*/
${preImport}
import { ScalarsEnumsHash${
hasUnions ? ', SchemaUnionsKey' : ''
} } from "gqless";
${hasUnions ? 'import { SchemaUnionsKey } from "gqless";' : ''}
${await codegenResultPromise}
export${
isJavascriptOutput ? ' declare' : ''
} const scalarsEnumsHash: ScalarsEnumsHash${
} const scalarsEnumsHash: import("gqless").ScalarsEnumsHash${
isJavascriptOutput ? ';' : ` = ${JSON.stringify(scalarsEnumsHash)};`
}
export${isJavascriptOutput ? ' declare' : ''} const generatedSchema ${
Expand Down
28 changes: 9 additions & 19 deletions packages/cli/test/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ test('basic functionality works', async () => {
// This should be included
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -66,7 +64,7 @@ test('basic functionality works', async () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Int: true,
Boolean: true,
Expand Down Expand Up @@ -382,8 +380,6 @@ test('custom scalars works', async () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -402,7 +398,7 @@ test('custom scalars works', async () => {
Custom: 'hello world';
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
Custom: true,
Boolean: true,
String: true,
Expand Down Expand Up @@ -577,7 +573,7 @@ describe('feature complete app', () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash, SchemaUnionsKey } from 'gqless';
import { SchemaUnionsKey } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
Expand Down Expand Up @@ -620,7 +616,7 @@ describe('feature complete app', () => {
scal?: Maybe<Scalars['ExampleScalar']>;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
ExampleScalar: true,
GreetingsEnum: true,
OtherEnum: true,
Expand Down Expand Up @@ -927,8 +923,6 @@ describe('mutation', () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -946,7 +940,7 @@ describe('mutation', () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down Expand Up @@ -1059,8 +1053,6 @@ describe('subscription', () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -1078,7 +1070,7 @@ describe('subscription', () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down Expand Up @@ -1363,7 +1355,7 @@ test('javascript output works', async () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash, SchemaUnionsKey } from 'gqless';
import { SchemaUnionsKey } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
Expand All @@ -1382,7 +1374,7 @@ test('javascript output works', async () => {
Float: number;
}
export declare const scalarsEnumsHash: ScalarsEnumsHash;
export declare const scalarsEnumsHash: import('gqless').ScalarsEnumsHash;
export declare const generatedSchema: {
query: { __typename: { __type: 'String!' }; hello: { __type: 'String!' } };
mutation: {};
Expand Down Expand Up @@ -1622,8 +1614,6 @@ test('ignoreArgs transform', async () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -1641,7 +1631,7 @@ test('ignoreArgs transform', async () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Int: true,
Boolean: true,
Expand Down
28 changes: 7 additions & 21 deletions packages/cli/test/inspectWriteGenerate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ test('basic inspectWriteGenerate functionality', async () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -156,7 +154,7 @@ test('basic inspectWriteGenerate functionality', async () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down Expand Up @@ -322,8 +320,6 @@ describe('from file', () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -341,7 +337,7 @@ describe('from file', () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
Int: true,
Boolean: true,
String: true,
Expand Down Expand Up @@ -509,8 +505,6 @@ describe('from file', () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -528,7 +522,7 @@ describe('from file', () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down Expand Up @@ -695,8 +689,6 @@ describe('from file', () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -714,7 +706,7 @@ describe('from file', () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down Expand Up @@ -920,8 +912,6 @@ test('specify generateOptions to inspectWriteGenerate', async () => {
// This should be included
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -939,7 +929,7 @@ test('specify generateOptions to inspectWriteGenerate', async () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down Expand Up @@ -1058,8 +1048,6 @@ describe('inspect headers', () => {
*/
// This should be included
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -1077,7 +1065,7 @@ describe('inspect headers', () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down Expand Up @@ -1273,8 +1261,6 @@ describe('CLI behavior', () => {
* GQLESS AUTO-GENERATED CODE: PLEASE DO NOT MODIFY MANUALLY
*/
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -1292,7 +1278,7 @@ describe('CLI behavior', () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down
8 changes: 2 additions & 6 deletions packages/cli/test/writeGenerate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ test('generates code and writes existing file', async () => {
*/
// This should be included
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -88,7 +86,7 @@ test('generates code and writes existing file', async () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down Expand Up @@ -176,8 +174,6 @@ test('creates dir, generates code and writes new file', async () => {
*/
// This should be included
import { ScalarsEnumsHash } from 'gqless';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand All @@ -195,7 +191,7 @@ test('creates dir, generates code and writes new file', async () => {
Float: number;
}
export const scalarsEnumsHash: ScalarsEnumsHash = {
export const scalarsEnumsHash: import('gqless').ScalarsEnumsHash = {
String: true,
Boolean: true,
};
Expand Down
30 changes: 30 additions & 0 deletions packages/gqless/src/Client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface InnerClientState {
readonly queryFetcher: QueryFetcher;
readonly schemaUnions: SchemaUnions;
readonly normalizationHandler: NormalizationHandler | undefined;
defaults: CoreClientDefaults;
}

export interface SubscribeEvents {
Expand Down Expand Up @@ -103,6 +104,32 @@ export interface SubscriptionsClient {
): void;
}

export interface CoreClientDefaults {
/**
* `resolved` defaults
*/
resolved?: {
/**
* Set the default `noCache` option
*
* @default false
*/
noCache?: boolean;
/**
* Set the default `noCache` option
*
* @default false
*/
refetch?: boolean;
/**
* Set the default `retry` strategy
*
* @default false
*/
retry?: RetryOptions;
};
}

export interface ClientOptions<
ObjectTypesNames extends string = never,
SchemaObjectTypes extends {
Expand All @@ -120,6 +147,7 @@ export interface ClientOptions<
| NormalizationOptions<ObjectTypesNames, SchemaObjectTypes>
| boolean;
subscriptionsClient?: SubscriptionsClient;
defaults?: CoreClientDefaults;
}

export interface MutateHelpers<
Expand Down Expand Up @@ -218,6 +246,7 @@ export function createClient<
retry,
normalization = true,
subscriptionsClient,
defaults = {},
}: ClientOptions<
ObjectTypesNames,
ObjectTypes
Expand Down Expand Up @@ -261,6 +290,7 @@ export function createClient<
queryFetcher,
schemaUnions: createSchemaUnions(schema),
normalizationHandler,
defaults,
};

const {
Expand Down
Loading

1 comment on commit 422eb9a

@vercel
Copy link

@vercel vercel bot commented on 422eb9a May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.