@hazeljs/graphql 0.2.0-beta.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +192 -0
- package/README.md +120 -0
- package/dist/client/decorators.d.ts +44 -0
- package/dist/client/decorators.d.ts.map +1 -0
- package/dist/client/decorators.js +72 -0
- package/dist/client/graphql.client.d.ts +25 -0
- package/dist/client/graphql.client.d.ts.map +1 -0
- package/dist/client/graphql.client.js +47 -0
- package/dist/decorators/field.decorator.d.ts +23 -0
- package/dist/decorators/field.decorator.d.ts.map +1 -0
- package/dist/decorators/field.decorator.js +37 -0
- package/dist/decorators/object-type.decorator.d.ts +21 -0
- package/dist/decorators/object-type.decorator.d.ts.map +1 -0
- package/dist/decorators/object-type.decorator.js +34 -0
- package/dist/decorators/query-mutation.decorator.d.ts +25 -0
- package/dist/decorators/query-mutation.decorator.d.ts.map +1 -0
- package/dist/decorators/query-mutation.decorator.js +62 -0
- package/dist/decorators/resolver.decorator.d.ts +25 -0
- package/dist/decorators/resolver.decorator.d.ts.map +1 -0
- package/dist/decorators/resolver.decorator.js +35 -0
- package/dist/graphql.module.d.ts +31 -0
- package/dist/graphql.module.d.ts.map +1 -0
- package/dist/graphql.module.js +63 -0
- package/dist/graphql.server.d.ts +34 -0
- package/dist/graphql.server.d.ts.map +1 -0
- package/dist/graphql.server.js +74 -0
- package/dist/graphql.types.d.ts +36 -0
- package/dist/graphql.types.d.ts.map +1 -0
- package/dist/graphql.types.js +5 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/schema-builder.d.ts +9 -0
- package/dist/schema-builder.d.ts.map +1 -0
- package/dist/schema-builder.js +142 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2024 HazelJS Team
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
22
|
+
|
|
23
|
+
1. Definitions.
|
|
24
|
+
|
|
25
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
26
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
27
|
+
|
|
28
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
29
|
+
the copyright owner that is granting the License.
|
|
30
|
+
|
|
31
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
32
|
+
other entities that control, are controlled by, or are under common
|
|
33
|
+
control with that entity. For the purposes of this definition,
|
|
34
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
35
|
+
direction or management of such entity, whether by contract or
|
|
36
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
37
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
38
|
+
|
|
39
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
40
|
+
exercising permissions granted by this License.
|
|
41
|
+
|
|
42
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
43
|
+
including but not limited to software source code, documentation
|
|
44
|
+
source, and configuration files.
|
|
45
|
+
|
|
46
|
+
"Object" form shall mean any form resulting from mechanical
|
|
47
|
+
transformation or translation of a Source form, including but
|
|
48
|
+
not limited to compiled object code, generated documentation,
|
|
49
|
+
and conversions to other media types.
|
|
50
|
+
|
|
51
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
52
|
+
Object form, made available under the License, as indicated by a
|
|
53
|
+
copyright notice that is included in or attached to the work
|
|
54
|
+
(an example is provided in the Appendix below).
|
|
55
|
+
|
|
56
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
57
|
+
form, that is based on (or derived from) the Work and for which the
|
|
58
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
59
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
60
|
+
of this License, Derivative Works shall not include works that remain
|
|
61
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
62
|
+
the Work and Derivative Works thereof.
|
|
63
|
+
|
|
64
|
+
"Contribution" shall mean any work of authorship, including
|
|
65
|
+
the original version of the Work and any modifications or additions
|
|
66
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
67
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
68
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
69
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
70
|
+
means any form of electronic, verbal, or written communication sent
|
|
71
|
+
to the Licensor or its representatives, including but not limited to
|
|
72
|
+
communication on electronic mailing lists, source code control systems,
|
|
73
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
74
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
75
|
+
excluding communication that is conspicuously marked or otherwise
|
|
76
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
77
|
+
|
|
78
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
79
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
80
|
+
subsequently incorporated within the Work.
|
|
81
|
+
|
|
82
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
83
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
84
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
85
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
86
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
87
|
+
Work and such Derivative Works in Source or Object form.
|
|
88
|
+
|
|
89
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
90
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
91
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
92
|
+
(except as stated in this section) patent license to make, have made,
|
|
93
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
94
|
+
where such license applies only to those patent claims licensable
|
|
95
|
+
by such Contributor that are necessarily infringed by their
|
|
96
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
97
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
98
|
+
institute patent litigation against any entity (including a
|
|
99
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
100
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
101
|
+
or contributory patent infringement, then any patent licenses
|
|
102
|
+
granted to You under this License for that Work shall terminate
|
|
103
|
+
as of the date such litigation is filed.
|
|
104
|
+
|
|
105
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
106
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
107
|
+
modifications, and in Source or Object form, provided that You
|
|
108
|
+
meet the following conditions:
|
|
109
|
+
|
|
110
|
+
(a) You must give any other recipients of the Work or
|
|
111
|
+
Derivative Works a copy of this License; and
|
|
112
|
+
|
|
113
|
+
(b) You must cause any modified files to carry prominent notices
|
|
114
|
+
stating that You changed the files; and
|
|
115
|
+
|
|
116
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
117
|
+
that You distribute, all copyright, patent, trademark, and
|
|
118
|
+
attribution notices from the Source form of the Work,
|
|
119
|
+
excluding those notices that do not pertain to any part of
|
|
120
|
+
the Derivative Works; and
|
|
121
|
+
|
|
122
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
123
|
+
distribution, then any Derivative Works that You distribute must
|
|
124
|
+
include a readable copy of the attribution notices contained
|
|
125
|
+
within such NOTICE file, excluding those notices that do not
|
|
126
|
+
pertain to any part of the Derivative Works, in at least one
|
|
127
|
+
of the following places: within a NOTICE text file distributed
|
|
128
|
+
as part of the Derivative Works; within the Source form or
|
|
129
|
+
documentation, if provided along with the Derivative Works; or,
|
|
130
|
+
within a display generated by the Derivative Works, if and
|
|
131
|
+
wherever such third-party notices normally appear. The contents
|
|
132
|
+
of the NOTICE file are for informational purposes only and
|
|
133
|
+
do not modify the License. You may add Your own attribution
|
|
134
|
+
notices within Derivative Works that You distribute, alongside
|
|
135
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
136
|
+
that such additional attribution notices cannot be construed
|
|
137
|
+
as modifying the License.
|
|
138
|
+
|
|
139
|
+
You may add Your own copyright statement to Your modifications and
|
|
140
|
+
may provide additional or different license terms and conditions
|
|
141
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
142
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
143
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
144
|
+
the conditions stated in this License.
|
|
145
|
+
|
|
146
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
147
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
148
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
149
|
+
this License, without any additional terms or conditions.
|
|
150
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
151
|
+
the terms of any separate license agreement you may have executed
|
|
152
|
+
with Licensor regarding such Contributions.
|
|
153
|
+
|
|
154
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
155
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
156
|
+
except as required for reasonable and customary use in describing the
|
|
157
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
158
|
+
|
|
159
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
160
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
161
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
162
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
163
|
+
implied, including, without limitation, any warranties or conditions
|
|
164
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
165
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
166
|
+
appropriateness of using or redistributing the Work and assume any
|
|
167
|
+
risks associated with Your exercise of permissions under this License.
|
|
168
|
+
|
|
169
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
170
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
171
|
+
unless required by applicable law (such as deliberate and grossly
|
|
172
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
173
|
+
liable to You for damages, including any direct, indirect, special,
|
|
174
|
+
incidental, or consequential damages of any character arising as a
|
|
175
|
+
result of this License or out of the use or inability to use the
|
|
176
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
177
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
178
|
+
other commercial damages or losses), even if such Contributor
|
|
179
|
+
has been advised of the possibility of such damages.
|
|
180
|
+
|
|
181
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
182
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
183
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
184
|
+
or other liability obligations and/or rights consistent with this
|
|
185
|
+
License. However, in accepting such obligations, You may act only
|
|
186
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
187
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
188
|
+
defend, and hold each Contributor harmless for any liability
|
|
189
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
190
|
+
of your accepting any such warranty or additional liability.
|
|
191
|
+
|
|
192
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @hazeljs/graphql
|
|
2
|
+
|
|
3
|
+
GraphQL server and client for HazelJS with decorator-based schema and typed client.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @hazeljs/graphql @hazeljs/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Server Usage
|
|
12
|
+
|
|
13
|
+
### 1. Define Object Types (optional, for complex return types)
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { ObjectType, Field } from '@hazeljs/graphql';
|
|
17
|
+
|
|
18
|
+
@ObjectType()
|
|
19
|
+
class User {
|
|
20
|
+
@Field()
|
|
21
|
+
id: string;
|
|
22
|
+
|
|
23
|
+
@Field()
|
|
24
|
+
name: string;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Create Resolvers
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Injectable } from '@hazeljs/core';
|
|
32
|
+
import { Resolver, Query, Mutation, Arg } from '@hazeljs/graphql';
|
|
33
|
+
|
|
34
|
+
@Injectable()
|
|
35
|
+
@Resolver()
|
|
36
|
+
export class UserResolver {
|
|
37
|
+
@Query()
|
|
38
|
+
hello() {
|
|
39
|
+
return 'Hello, GraphQL!';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Query()
|
|
43
|
+
user(@Arg('id') id: string) {
|
|
44
|
+
return { id, name: 'John Doe' };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Mutation()
|
|
48
|
+
createUser(@Arg('name') name: string) {
|
|
49
|
+
return { id: '1', name };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 3. Register GraphQL Module
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { HazelModule } from '@hazeljs/core';
|
|
58
|
+
import { GraphQLModule } from '@hazeljs/graphql';
|
|
59
|
+
import { UserResolver } from './user.resolver';
|
|
60
|
+
|
|
61
|
+
@HazelModule({
|
|
62
|
+
imports: [
|
|
63
|
+
GraphQLModule.forRoot({
|
|
64
|
+
path: '/graphql',
|
|
65
|
+
resolvers: [UserResolver],
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
})
|
|
69
|
+
export class AppModule {}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 4. Start the App
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { HazelApp } from '@hazeljs/core';
|
|
76
|
+
|
|
77
|
+
const app = new HazelApp(AppModule);
|
|
78
|
+
app.listen(3000);
|
|
79
|
+
// GraphQL available at http://localhost:3000/graphql
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Client Usage
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { GraphQLClient } from '@hazeljs/graphql';
|
|
86
|
+
|
|
87
|
+
const client = new GraphQLClient({
|
|
88
|
+
url: 'http://localhost:3000/graphql',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Query
|
|
92
|
+
const data = await client.query(`
|
|
93
|
+
query {
|
|
94
|
+
hello
|
|
95
|
+
user(id: "1") { id name }
|
|
96
|
+
}
|
|
97
|
+
`);
|
|
98
|
+
|
|
99
|
+
// Mutation
|
|
100
|
+
const result = await client.mutate(`
|
|
101
|
+
mutation {
|
|
102
|
+
createUser(name: "Alice") { id name }
|
|
103
|
+
}
|
|
104
|
+
`);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Decorators Reference
|
|
108
|
+
|
|
109
|
+
### Server
|
|
110
|
+
- `@ObjectType(name?)` - Mark class as GraphQL object type
|
|
111
|
+
- `@Field(name?)` - Mark property/method as field
|
|
112
|
+
- `@Resolver(name?)` - Mark class as resolver
|
|
113
|
+
- `@Query(name?)` - Mark method as Query field
|
|
114
|
+
- `@Mutation(name?)` - Mark method as Mutation field
|
|
115
|
+
- `@Arg(name, type?)` - Mark parameter as GraphQL argument
|
|
116
|
+
|
|
117
|
+
### Client
|
|
118
|
+
- `@GraphQLClientClass(url, headers?)` - Mark class as GraphQL client
|
|
119
|
+
- `@GraphQLQuery()` - Mark method as query executor
|
|
120
|
+
- `@GraphQLMutation()` - Mark method as mutation executor
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Decorator for a client method that executes a GraphQL query
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* @GraphQLClientClass('http://localhost:3000/graphql')
|
|
8
|
+
* class UserClient {
|
|
9
|
+
* @GraphQLQuery()
|
|
10
|
+
* async getUser(id: string) {
|
|
11
|
+
* return `query { user(id: "${id}") { id name } }`;
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The method should return the GraphQL query string (or use a template literal)
|
|
17
|
+
*/
|
|
18
|
+
export declare function GraphQLQuery(): MethodDecorator;
|
|
19
|
+
/**
|
|
20
|
+
* Decorator for a client method that executes a GraphQL mutation
|
|
21
|
+
*/
|
|
22
|
+
export declare function GraphQLMutation(): MethodDecorator;
|
|
23
|
+
/**
|
|
24
|
+
* Class decorator - marks a class as a GraphQL client and injects the client
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* @GraphQLClientClass('http://localhost:3000/graphql')
|
|
29
|
+
* class ApiClient {
|
|
30
|
+
* constructor(public client: GraphQLClient) {}
|
|
31
|
+
*
|
|
32
|
+
* @GraphQLQuery()
|
|
33
|
+
* async hello() {
|
|
34
|
+
* return 'query { hello }';
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function GraphQLClientClass(url: string, headers?: Record<string, string>): ClassDecorator;
|
|
40
|
+
export declare function getGraphQLClientConfig(target: object): {
|
|
41
|
+
url: string;
|
|
42
|
+
headers: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../src/client/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAK1B;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,IAAI,eAAe,CAO9C;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,eAAe,CAOjD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,cAAc,CAKhG;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG;IACtD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC,CAKA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLQuery = GraphQLQuery;
|
|
4
|
+
exports.GraphQLMutation = GraphQLMutation;
|
|
5
|
+
exports.GraphQLClientClass = GraphQLClientClass;
|
|
6
|
+
exports.getGraphQLClientConfig = getGraphQLClientConfig;
|
|
7
|
+
require("reflect-metadata");
|
|
8
|
+
const GQL_QUERY_METADATA = Symbol('graphql:client:query');
|
|
9
|
+
const GQL_MUTATION_METADATA = Symbol('graphql:client:mutation');
|
|
10
|
+
/**
|
|
11
|
+
* Decorator for a client method that executes a GraphQL query
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* @GraphQLClientClass('http://localhost:3000/graphql')
|
|
16
|
+
* class UserClient {
|
|
17
|
+
* @GraphQLQuery()
|
|
18
|
+
* async getUser(id: string) {
|
|
19
|
+
* return `query { user(id: "${id}") { id name } }`;
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The method should return the GraphQL query string (or use a template literal)
|
|
25
|
+
*/
|
|
26
|
+
function GraphQLQuery() {
|
|
27
|
+
return (target, propertyKey, descriptor) => {
|
|
28
|
+
const existing = Reflect.getMetadata(GQL_QUERY_METADATA, target.constructor) || [];
|
|
29
|
+
existing.push(String(propertyKey));
|
|
30
|
+
Reflect.defineMetadata(GQL_QUERY_METADATA, existing, target.constructor);
|
|
31
|
+
return descriptor;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Decorator for a client method that executes a GraphQL mutation
|
|
36
|
+
*/
|
|
37
|
+
function GraphQLMutation() {
|
|
38
|
+
return (target, propertyKey, descriptor) => {
|
|
39
|
+
const existing = Reflect.getMetadata(GQL_MUTATION_METADATA, target.constructor) || [];
|
|
40
|
+
existing.push(String(propertyKey));
|
|
41
|
+
Reflect.defineMetadata(GQL_MUTATION_METADATA, existing, target.constructor);
|
|
42
|
+
return descriptor;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Class decorator - marks a class as a GraphQL client and injects the client
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* @GraphQLClientClass('http://localhost:3000/graphql')
|
|
51
|
+
* class ApiClient {
|
|
52
|
+
* constructor(public client: GraphQLClient) {}
|
|
53
|
+
*
|
|
54
|
+
* @GraphQLQuery()
|
|
55
|
+
* async hello() {
|
|
56
|
+
* return 'query { hello }';
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function GraphQLClientClass(url, headers) {
|
|
62
|
+
return (target) => {
|
|
63
|
+
Reflect.defineMetadata('graphql:client:url', url, target);
|
|
64
|
+
Reflect.defineMetadata('graphql:client:headers', headers ?? {}, target);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function getGraphQLClientConfig(target) {
|
|
68
|
+
return {
|
|
69
|
+
url: Reflect.getMetadata('graphql:client:url', target) ?? '',
|
|
70
|
+
headers: Reflect.getMetadata('graphql:client:headers', target) ?? {},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed GraphQL client for HazelJS
|
|
3
|
+
* Execute queries and mutations with optional decorator-based API
|
|
4
|
+
*/
|
|
5
|
+
export interface GraphQLClientOptions {
|
|
6
|
+
url: string;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Simple GraphQL client - fetch-based for Node and browser
|
|
11
|
+
*/
|
|
12
|
+
export declare class GraphQLClient {
|
|
13
|
+
private readonly options;
|
|
14
|
+
constructor(options: GraphQLClientOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Execute a GraphQL query
|
|
17
|
+
*/
|
|
18
|
+
query<T = unknown>(operation: string, variables?: Record<string, unknown>): Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Execute a GraphQL mutation
|
|
21
|
+
*/
|
|
22
|
+
mutate<T = unknown>(operation: string, variables?: Record<string, unknown>): Promise<T>;
|
|
23
|
+
private request;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=graphql.client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.client.d.ts","sourceRoot":"","sources":["../../src/client/graphql.client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,oBAAoB;IAE1D;;OAEG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAI5F;;OAEG;IACG,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;YAI/E,OAAO;CA4BtB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Typed GraphQL client for HazelJS
|
|
4
|
+
* Execute queries and mutations with optional decorator-based API
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.GraphQLClient = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Simple GraphQL client - fetch-based for Node and browser
|
|
10
|
+
*/
|
|
11
|
+
class GraphQLClient {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Execute a GraphQL query
|
|
17
|
+
*/
|
|
18
|
+
async query(operation, variables) {
|
|
19
|
+
return this.request(operation, variables, 'query');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Execute a GraphQL mutation
|
|
23
|
+
*/
|
|
24
|
+
async mutate(operation, variables) {
|
|
25
|
+
return this.request(operation, variables, 'mutation');
|
|
26
|
+
}
|
|
27
|
+
async request(operation, variables, opType = 'query') {
|
|
28
|
+
const body = JSON.stringify(opType === 'mutation' ? { query: operation, variables } : { query: operation, variables });
|
|
29
|
+
const res = await fetch(this.options.url, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
...this.options.headers,
|
|
34
|
+
},
|
|
35
|
+
body,
|
|
36
|
+
});
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
throw new Error(`GraphQL request failed: ${res.status} ${res.statusText}`);
|
|
39
|
+
}
|
|
40
|
+
const json = (await res.json());
|
|
41
|
+
if (json.errors?.length) {
|
|
42
|
+
throw new Error(json.errors.map((e) => e.message).join('; '));
|
|
43
|
+
}
|
|
44
|
+
return json.data;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.GraphQLClient = GraphQLClient;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { FieldMetadata } from '../graphql.types';
|
|
3
|
+
export declare const FIELD_METADATA_KEY: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* Marks a property or method as a GraphQL field
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @ObjectType()
|
|
10
|
+
* class User {
|
|
11
|
+
* @Field()
|
|
12
|
+
* id: string;
|
|
13
|
+
*
|
|
14
|
+
* @Field()
|
|
15
|
+
* fullName(): string {
|
|
16
|
+
* return `${this.firstName} ${this.lastName}`;
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function Field(nameOrOptions?: string | Partial<FieldMetadata>): PropertyDecorator & MethodDecorator;
|
|
22
|
+
export declare function getFieldMetadata(target: object): FieldMetadata[];
|
|
23
|
+
//# sourceMappingURL=field.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/field.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAO,MAAM,kBAAkB,eAA0B,CAAC;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CACnB,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,GAC9C,iBAAiB,GAAG,eAAe,CAUrC;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE,CAEhE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FIELD_METADATA_KEY = void 0;
|
|
4
|
+
exports.Field = Field;
|
|
5
|
+
exports.getFieldMetadata = getFieldMetadata;
|
|
6
|
+
require("reflect-metadata");
|
|
7
|
+
exports.FIELD_METADATA_KEY = Symbol('graphql:field');
|
|
8
|
+
/**
|
|
9
|
+
* Marks a property or method as a GraphQL field
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @ObjectType()
|
|
14
|
+
* class User {
|
|
15
|
+
* @Field()
|
|
16
|
+
* id: string;
|
|
17
|
+
*
|
|
18
|
+
* @Field()
|
|
19
|
+
* fullName(): string {
|
|
20
|
+
* return `${this.firstName} ${this.lastName}`;
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function Field(nameOrOptions) {
|
|
26
|
+
return (target, propertyKey, _descriptor) => {
|
|
27
|
+
const meta = typeof nameOrOptions === 'string'
|
|
28
|
+
? { name: nameOrOptions, type: undefined }
|
|
29
|
+
: { name: String(propertyKey), type: undefined, ...nameOrOptions };
|
|
30
|
+
const existing = Reflect.getMetadata(exports.FIELD_METADATA_KEY, target) || [];
|
|
31
|
+
existing.push({ ...meta, name: meta.name || String(propertyKey) });
|
|
32
|
+
Reflect.defineMetadata(exports.FIELD_METADATA_KEY, existing, target);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function getFieldMetadata(target) {
|
|
36
|
+
return Reflect.getMetadata(exports.FIELD_METADATA_KEY, target) || [];
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { ObjectTypeMetadata } from '../graphql.types';
|
|
3
|
+
export declare const OBJECT_TYPE_METADATA_KEY: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* Marks a class as a GraphQL object type
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @ObjectType()
|
|
10
|
+
* class User {
|
|
11
|
+
* @Field()
|
|
12
|
+
* id: string;
|
|
13
|
+
*
|
|
14
|
+
* @Field()
|
|
15
|
+
* name: string;
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function ObjectType(nameOrOptions?: string | ObjectTypeMetadata): ClassDecorator;
|
|
20
|
+
export declare function getObjectTypeMetadata(target: object): ObjectTypeMetadata | undefined;
|
|
21
|
+
//# sourceMappingURL=object-type.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-type.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/object-type.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,eAAO,MAAM,wBAAwB,eAAgC,CAAC;AAEtE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,cAAc,CAQtF;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAIpF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OBJECT_TYPE_METADATA_KEY = void 0;
|
|
4
|
+
exports.ObjectType = ObjectType;
|
|
5
|
+
exports.getObjectTypeMetadata = getObjectTypeMetadata;
|
|
6
|
+
require("reflect-metadata");
|
|
7
|
+
exports.OBJECT_TYPE_METADATA_KEY = Symbol('graphql:object-type');
|
|
8
|
+
/**
|
|
9
|
+
* Marks a class as a GraphQL object type
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* @ObjectType()
|
|
14
|
+
* class User {
|
|
15
|
+
* @Field()
|
|
16
|
+
* id: string;
|
|
17
|
+
*
|
|
18
|
+
* @Field()
|
|
19
|
+
* name: string;
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function ObjectType(nameOrOptions) {
|
|
24
|
+
return (target) => {
|
|
25
|
+
const meta = typeof nameOrOptions === 'string'
|
|
26
|
+
? { name: nameOrOptions }
|
|
27
|
+
: (nameOrOptions ?? { name: target.name });
|
|
28
|
+
Reflect.defineMetadata(exports.OBJECT_TYPE_METADATA_KEY, meta, target);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function getObjectTypeMetadata(target) {
|
|
32
|
+
const ctor = typeof target === 'function' ? target : target.constructor;
|
|
33
|
+
return Reflect.getMetadata(exports.OBJECT_TYPE_METADATA_KEY, ctor ?? target);
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import type { QueryMetadata, MutationMetadata, ArgMetadata } from '../graphql.types';
|
|
3
|
+
export declare const QUERY_METADATA_KEY: unique symbol;
|
|
4
|
+
export declare const MUTATION_METADATA_KEY: unique symbol;
|
|
5
|
+
export declare const ARG_METADATA_KEY: unique symbol;
|
|
6
|
+
/**
|
|
7
|
+
* Marks a method as a GraphQL Query
|
|
8
|
+
*/
|
|
9
|
+
export declare function Query(nameOrOptions?: string | Partial<QueryMetadata>): MethodDecorator;
|
|
10
|
+
/**
|
|
11
|
+
* Marks a method as a GraphQL Mutation
|
|
12
|
+
*/
|
|
13
|
+
export declare function Mutation(nameOrOptions?: string | Partial<MutationMetadata>): MethodDecorator;
|
|
14
|
+
/**
|
|
15
|
+
* Marks a parameter as a GraphQL argument
|
|
16
|
+
*/
|
|
17
|
+
export declare function Arg(nameOrOptions: string | Partial<ArgMetadata>, type?: unknown): ParameterDecorator;
|
|
18
|
+
export declare function getQueryMetadata(target: object): Array<QueryMetadata & {
|
|
19
|
+
method: string;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function getMutationMetadata(target: object): Array<MutationMetadata & {
|
|
22
|
+
method: string;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function getArgMetadata(target: object, propertyKey: string | symbol): ArgMetadata[];
|
|
25
|
+
//# sourceMappingURL=query-mutation.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-mutation.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/query-mutation.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAErF,eAAO,MAAM,kBAAkB,eAA0B,CAAC;AAC1D,eAAO,MAAM,qBAAqB,eAA6B,CAAC;AAChE,eAAO,MAAM,gBAAgB,eAAwB,CAAC;AAEtD;;GAEG;AACH,wBAAgB,KAAK,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,eAAe,CAUtF;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,GAAG,eAAe,CAU5F;AAED;;GAEG;AACH,wBAAgB,GAAG,CACjB,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,EAC5C,IAAI,CAAC,EAAE,OAAO,GACb,kBAAkB,CAWpB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAE1F;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,gBAAgB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAEhG;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,WAAW,EAAE,CAE1F"}
|