Skip to content

Commit 30787dd

Browse files
committed
fix!: GraphtonSettings now uses static properties instead of a floating const
1 parent 8f984c0 commit 30787dd

15 files changed

+455
-439
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ on:
33
workflow_dispatch:
44
inputs:
55
forceVersionType:
6-
description: 'Force specific versioning type'
7-
default: '-'
6+
description: "Force specific versioning type"
7+
default: "-"
88
type: choice
99
required: false
1010
options:
11-
- '-'
12-
- 'major'
13-
- 'minor'
14-
- 'patch'
11+
- "-"
12+
- "major"
13+
- "minor"
14+
- "patch"
1515

1616
jobs:
1717
release:

CHANGELOG.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,34 @@ All notable changes to this project will be documented in this file. See [standa
66

77
### [0.6.9](https://github.com/GraphtonLib/Graphton/compare/v0.6.8...v0.6.9) (2022-07-09)
88

9-
109
### Bug Fixes
1110

12-
* Export GraphtonBaseQuery ([e0507e4](https://github.com/GraphtonLib/Graphton/commit/e0507e45ce14c306265be9658d41447841f6336c))
11+
- Export GraphtonBaseQuery ([e0507e4](https://github.com/GraphtonLib/Graphton/commit/e0507e45ce14c306265be9658d41447841f6336c))
1312

1413
### [0.6.8](https://github.com/GraphtonLib/Graphton/compare/v0.6.7...v0.6.8) (2022-07-09)
1514

16-
1715
### Bug Fixes
1816

19-
* Scalar Properties rendering full type definition instead of just the name ([50bd7e5](https://github.com/GraphtonLib/Graphton/commit/50bd7e598bd0cb478e21ae435d0d5747df8f45c5))
20-
* **security:** Force minimist ^1.2.6 ([049bdc6](https://github.com/GraphtonLib/Graphton/commit/049bdc6e8e689bc967acb3c1423bbcb30645491a))
21-
* **security:** Force minimist ^1.2.6 ([0308b50](https://github.com/GraphtonLib/Graphton/commit/0308b503a53b613c20b2890ae687b1726736be85))
17+
- Scalar Properties rendering full type definition instead of just the name ([50bd7e5](https://github.com/GraphtonLib/Graphton/commit/50bd7e598bd0cb478e21ae435d0d5747df8f45c5))
18+
- **security:** Force minimist ^1.2.6 ([0308b50](https://github.com/GraphtonLib/Graphton/commit/0308b503a53b613c20b2890ae687b1726736be85))
2219

2320
### [0.6.7](https://github.com/GraphtonLib/Graphton/compare/v0.6.6...v0.6.7) (2022-07-09)
2421

25-
2622
### Bug Fixes
2723

28-
* Bug where enum was ignored in return type builders ([31507e2](https://github.com/GraphtonLib/Graphton/commit/31507e2b98f15a35a9abfabacb4e12cd7aaade79))
24+
- Bug where enum was ignored in return type builders ([31507e2](https://github.com/GraphtonLib/Graphton/commit/31507e2b98f15a35a9abfabacb4e12cd7aaade79))
2925

3026
### [0.6.6](https://github.com/GraphtonLib/Graphton/compare/v0.6.5...v0.6.6) (2022-05-01)
3127

3228
### [0.6.5](https://github.com/GraphtonLib/Graphton/compare/v0.6.4...v0.6.5) (2022-05-01)
3329

34-
3530
### Features
3631

37-
* Adds (alias) types for scalars and customization of custom scalar types ([ea75f69](https://github.com/GraphtonLib/Graphton/commit/ea75f69e767b5329bfe494a34877fa79e3fd00e2))
38-
32+
- Adds (alias) types for scalars and customization of custom scalar types ([ea75f69](https://github.com/GraphtonLib/Graphton/commit/ea75f69e767b5329bfe494a34877fa79e3fd00e2))
3933

4034
### Bug Fixes
4135

42-
* Add stacktrace to argify error ([c947e4b](https://github.com/GraphtonLib/Graphton/commit/c947e4bb11659602ffeeeb821a4593b4d93bc217))
36+
- Add stacktrace to argify error ([c947e4b](https://github.com/GraphtonLib/Graphton/commit/c947e4bb11659602ffeeeb821a4593b4d93bc217))
4337

4438
### [0.6.4](https://github.com/GraphtonLib/Graphton/compare/v0.6.3...v0.6.4) (2022-01-23)
4539

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,21 +388,27 @@ Gives you a list of possible enums
388388

389389
### GraphtonSettings
390390

391-
Use this to change the global settings used by Graphton on the fly!
391+
Graphton uses the static properties of this class, so you can customize these.
392392

393-
#### setDefaultHeaders
393+
#### headers
394394

395-
> static setDefaultHeaders(headers: Record<string, string>): void
395+
> public static headers = { };
396396
397397
Set the headers for each following request to the server.
398398

399-
#### setDefaultUrl
399+
```typescript
400+
GraphtonSettings.headers = { Authorization: "Bearer 123abc" };
401+
```
402+
403+
#### graphqlEndpoint
400404

401-
> static setDefaultUrl(defaultUrl: string): void
405+
> public static graphqlEndpoint: string = '<URL of retrospection>';
402406
403-
Set the URL to the GraphQL server.
407+
Set the URL to the GraphQL endpoint, defaults to the URL used when generating the file.
404408

405-
> NOTE: If you generated the Graphton file from a URL, this will also be the URL that's set if you havn't called this function yet. Use this if your GraphQL server differs from the one you introspected from.
409+
```typescript
410+
GraphtonSettings.graphqlEndpoint = "https://mycoolexample.app/graphql";
411+
```
406412

407413
## Links
408414

example/graphtonGeneratedJavascript.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@
44
* @see https://github.com/GraphtonLib/Graphton
55
**/
66
// REGION: Base classes
7-
const settings = {
8-
defaultHeaders: {},
9-
defaultUrl: "",
10-
};
117
export class GraphtonSettings {
12-
static setDefaultHeaders(headers) {
13-
settings.defaultHeaders = headers;
14-
}
15-
static setDefaultUrl(defaultUrl) {
16-
settings.defaultUrl = defaultUrl;
17-
}
8+
static headers = {};
9+
static graphqlEndpoint = "";
1810
}
1911
import axios from "axios";
2012
export class GraphtonBaseQuery {
@@ -55,12 +47,12 @@ export class GraphtonBaseQuery {
5547
*/
5648
async execute(requestOptions = {}) {
5749
const response = await axios.post(
58-
requestOptions?.url || settings.defaultUrl,
50+
requestOptions?.url || GraphtonSettings.graphqlEndpoint,
5951
{ query: this.toQuery() },
6052
{
6153
headers: {
6254
"Content-Type": "application/json",
63-
...settings.defaultHeaders,
55+
...GraphtonSettings.headers,
6456
...requestOptions?.headers,
6557
},
6658
}

example/graphtonGeneratedTypescript.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,9 @@
55
**/
66

77
// REGION: Base classes
8-
const settings = {
9-
defaultHeaders: {},
10-
defaultUrl: "",
11-
};
12-
138
export class GraphtonSettings {
14-
public static setDefaultHeaders(headers: Record<string, string>): void {
15-
settings.defaultHeaders = headers;
16-
}
17-
18-
public static setDefaultUrl(defaultUrl: string): void {
19-
settings.defaultUrl = defaultUrl;
20-
}
9+
public static headers: Record<string, string> = {};
10+
public static graphqlEndpoint: string = "";
2111
}
2212

2313
import type { AxiosResponse } from "axios";
@@ -102,12 +92,12 @@ export abstract class GraphtonBaseQuery<T> {
10292
*/
10393
protected async execute(requestOptions: RequestOptions = {}): Promise<QueryResponse> {
10494
const response = await axios.post(
105-
requestOptions?.url || settings.defaultUrl,
95+
requestOptions?.url || GraphtonSettings.graphqlEndpoint,
10696
{ query: this.toQuery() },
10797
{
10898
headers: {
10999
"Content-Type": "application/json",
110-
...settings.defaultHeaders,
100+
...GraphtonSettings.headers,
111101
...requestOptions?.headers,
112102
},
113103
}

src/commands/GenerateCommand.d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { GenerateCommandOptions } from "../types/Generator";
22
export default class GenerateCommand {
3-
private gqlSchema;
4-
generate(schemaUri: string, options: GenerateCommandOptions): Promise<void>;
5-
private generateScalarTypeAliases;
6-
private generateObjectTypes;
7-
private generateReturnTypeBuilders;
8-
private generateEnumTypes;
9-
private generateQueryFactory;
10-
private argsToMethodParameters;
11-
private toTypeAppend;
12-
private returnTypeInfo;
3+
private gqlSchema;
4+
generate(schemaUri: string, options: GenerateCommandOptions): Promise<void>;
5+
private generateScalarTypeAliases;
6+
private generateObjectTypes;
7+
private generateReturnTypeBuilders;
8+
private generateEnumTypes;
9+
private generateQueryFactory;
10+
private argsToMethodParameters;
11+
private toTypeAppend;
12+
private returnTypeInfo;
1313
}

0 commit comments

Comments
 (0)