@ver-id/graphql-client 0.8.2

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/README.md ADDED
@@ -0,0 +1,246 @@
1
+ # @ver-id/graphql-client
2
+
3
+ [![npm version](https://badge.fury.io/js/@ver-id%2Fgraphql-client.svg)](https://www.npmjs.com/package/@ver-id/graphql-client)
4
+ [![Build Status](https://github.com/ver-id/verid-sdk-js-mono/workflows/CI/badge.svg)](https://github.com/ver-id/verid-sdk-js-mono/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18-green.svg)](https://nodejs.org/)
8
+
9
+ Type-safe GraphQL client for querying Ver.iD GraphQL APIs. Built with Apollo Client and fully type-generated from the GraphQL schema.
10
+
11
+ ## Features
12
+
13
+ - **Type-Safe**: Full TypeScript support with auto-generated types from GraphQL schema
14
+ - **Apollo Client**: Built on industry-standard Apollo Client
15
+ - **Automatic Authentication**: OAuth2 client credentials flow handled automatically
16
+ - **Error Handling**: Comprehensive error types for GraphQL, network, and validation errors
17
+ - **Helper functions**: Pre-built functions for common queries
18
+
19
+ ## Getting Started
20
+
21
+ ### Installation
22
+
23
+ Using [npm](https://npmjs.org) in your project directory run the following command:
24
+
25
+ ```bash
26
+ npm install @ver-id/graphql-client
27
+ ```
28
+
29
+ Using [yarn](https://yarnpkg.com/) in your project directory run the following command:
30
+
31
+ ```bash
32
+ yarn add @ver-id/graphql-client
33
+ ```
34
+
35
+ Using [pnpm](https://pnpm.io/) in your project directory run the following command:
36
+
37
+ ```bash
38
+ pnpm add @ver-id/graphql-client
39
+ ```
40
+
41
+ ### Create the GraphQL Client
42
+
43
+ Ver.iD GraphQL SDK provides a graphql client which is a thin wrapper over [Apollo Client](https://github.com/apollographql/apollo-client) featuring built-in authorization, caching and error handling.
44
+
45
+ It will initialize an instance of apollo client.
46
+
47
+ ```typescript
48
+ import { createVeridGraphQLClient } from '@ver-id/graphql-client';
49
+
50
+ const client = createVeridGraphQLClient({
51
+ endpoint: '<VERID_GRAPHQL_ENDPOINT>'',
52
+ authorizationServer: '<VERID_AUTHORIZATION_SERVER>'',
53
+ clientId: '<GRAPHQL_CLIENT_ID>',
54
+ clientSecret: 'GRAPHQL_CLIENT_SECRET',
55
+ });
56
+ ```
57
+
58
+ ### Use helper functions
59
+
60
+ All helper functions can be called with an instance of Apollo Client. You can use `createVeridGraphQLClient` to create one or create your own client.
61
+
62
+ ```typescript
63
+ import {
64
+ getAttribute,
65
+ getAttributes,
66
+ getAttributesWithHierarchy,
67
+ } from '@ver-id/graphql-client';
68
+
69
+ // Fetch a single attribute
70
+ const attribute = await getAttribute(client, 'attribute-uuid');
71
+
72
+ // Fetch multiple attributes
73
+ const attributes = await getAttributes(client, ['uuid1', 'uuid2']);
74
+
75
+ // Fetch attributes with full hierarchy (credential → issuer → scheme → provider)
76
+ const attributesDeep = await getAttributesWithHierarchy(client, ['uuid1']);
77
+ console.log(attributesDeep[0].credential.issuer.scheme.provider.name);
78
+ ```
79
+
80
+ ### Configuration
81
+
82
+ ```typescript
83
+ interface GraphQLClientOptions {
84
+ /** GraphQL API endpoint */
85
+ endpoint: string;
86
+
87
+ /** OAuth2 authorization server URL */
88
+ authorizationServer: string;
89
+
90
+ /** OAuth2 GraphQL client ID */
91
+ clientId: string;
92
+
93
+ /** OAuth2 GraphQL client secret */
94
+ clientSecret: string;
95
+
96
+ /** Optional Apollo Client cache (default: InMemoryCache) */
97
+ cache?: InMemoryCache;
98
+ }
99
+ ```
100
+
101
+ ### API Reference
102
+
103
+ #### Attributes
104
+
105
+ ```typescript
106
+ // Fetch single attribute
107
+ getAttribute(client: ApolloClient, uuid: UUID): Promise<AttributeEntity>
108
+ // Fetch multiple attributes
109
+ getAttributes(client: ApolloClient, uuids: UUID[]): Promise<AttributeEntity[]>
110
+ // Fetch attributes with full hierarchy (includes credential, issuer, scheme, provider)
111
+ getAttributesWithHierarchy(client: ApolloClient, uuids: UUID[]): Promise<AttributeEntityDeep[]>
112
+ ```
113
+
114
+ #### Credentials
115
+
116
+ ```typescript
117
+ // Fetch single credential
118
+ getCredential(client: ApolloClient, uuid: UUID): Promise<CredentialEntity>
119
+ // Fetch multiple credentials
120
+ getCredentials(client: ApolloClient, uuids: UUID[]): Promise<CredentialEntity[]>
121
+ ```
122
+
123
+ #### Issuers
124
+
125
+ ```typescript
126
+ // Fetch single issuer
127
+ getIssuer(client: ApolloClient, uuid: UUID): Promise<IssuerEntity>
128
+ // Fetch multiple issuers
129
+ getIssuers(client: ApolloClient, uuids: UUID[]): Promise<IssuerEntity[]>
130
+ ```
131
+
132
+ #### Schemes
133
+
134
+ ```typescript
135
+ // Fetch single scheme
136
+ getScheme(client: ApolloClient, uuid: UUID): Promise<SchemeEntity>
137
+ // Fetch multiple schemes
138
+ getSchemes(client: ApolloClient, uuids: UUID[]): Promise<SchemeEntity[]>
139
+ ```
140
+
141
+ #### Providers
142
+
143
+ ```typescript
144
+ // Fetch single provider
145
+ getProvider(client: ApolloClient, uuid: UUID): Promise<ProviderEntity>
146
+ // Fetch multiple providers
147
+ getProviders(client: ApolloClient, uuids: UUID[]): Promise<ProviderEntity[]>
148
+ ```
149
+
150
+ ## Advanced Usage
151
+
152
+ ### Custom Queries
153
+
154
+ You can write custom queries using the generated types:
155
+
156
+ ```typescript
157
+ import { graphql } from '@ver-id/graphql-client';
158
+ import type { ResultOf, VariablesOf } from '@graphql-typed-document-node/core';
159
+
160
+ const MyCustomQuery = graphql(`
161
+ query GetCustomData($uuid: UUID!) {
162
+ findAttribute(uuid: $uuid) {
163
+ uuid
164
+ name
165
+ credential {
166
+ name
167
+ }
168
+ }
169
+ }
170
+ `);
171
+
172
+ type QueryResult = ResultOf<typeof MyCustomQuery>;
173
+ type QueryVariables = VariablesOf<typeof MyCustomQuery>;
174
+
175
+ const { data } = await client.query({
176
+ query: MyCustomQuery,
177
+ variables: { uuid: 'attribute-uuid' },
178
+ });
179
+
180
+ // data is fully typed!
181
+ ```
182
+
183
+ See [CUSTOM_QUERIES.md](./CUSTOM_QUERIES.md) for detailed guide.
184
+
185
+ ### Generated Types
186
+
187
+ All GraphQL schema types are exported:
188
+
189
+ ```typescript
190
+ import type {
191
+ Attribute,
192
+ Credential,
193
+ Issuer,
194
+ Scheme,
195
+ Provider,
196
+ FindManyAttributesInput,
197
+ AttributeFilteringField,
198
+ FilteringType,
199
+ } from '@ver-id/graphql-client';
200
+ ```
201
+
202
+ ### Pre-Generated Query Documents
203
+
204
+ ```typescript
205
+ import {
206
+ FindAttributeDocument,
207
+ FindManyAttributesDocument,
208
+ FindManyAttributesDeepDocument,
209
+ FindCredentialDocument,
210
+ // ... and more
211
+ } from '@ver-id/graphql-client';
212
+ ```
213
+
214
+ ## Type Definitions
215
+
216
+ ### Entity Types
217
+
218
+ The SDK provides domain entity types that are flattened and simplified from the GraphQL schema:
219
+
220
+ - `AttributeEntity` - Attribute metadata
221
+ - `AttributeEntityDeep` - Attribute with full hierarchy
222
+ - `CredentialEntity` - Credential metadata
223
+ - `IssuerEntity` - Issuer metadata
224
+ - `SchemeEntity` - Scheme metadata
225
+ - `ProviderEntity` - Provider metadata
226
+
227
+ ### GraphQL Schema Types
228
+
229
+ Raw GraphQL types are also exported:
230
+
231
+ - `Attribute` - Raw GraphQL Attribute type
232
+ - `Credential` - Raw GraphQL Credential type
233
+ - etc.
234
+
235
+ ## Examples
236
+
237
+ See the [examples](./examples) directory.
238
+
239
+ ## Acknowledgments
240
+
241
+ - Built with TypeScript
242
+ - Powered by [apollo](https://github.com/apollographql/apollo-client)
243
+
244
+ ## License
245
+
246
+ MIT