lucernex-client
v0.3.3
Published
A Node based Lucernex client SDK
Readme
Lucernex API Client Library
This library is a client for the Lucernex API to be used in connector/integration projects.
Building
To build the library, run yarn build. This will compile the library into the dist folder.
Publishing
To publish the library, run npm publish. This will publish the library to the NPM registry. Make sure to update the package version.
Using in a project
To use this library in a project, just run 'yarn add lucernex-client'.
GraphQL Codegen
This project uses GraphQL Code Generator to automatically generate TypeScript types and client code from GraphQL queries.
Configuration
The codegen configuration is defined in codegen.ts. It:
- Fetches the GraphQL schema from the Lucernex GraphQL endpoint
- Reads GraphQL query documents from
src/graphql/docs/*.graphql - Generates TypeScript types in
src/graphql/generated/types.ts - Generates GraphQL Request client code in
src/graphql/generated/graphql-request.ts
To note: if this needs to be regenerated, the authorization header will need to be updated. To do this, use the /rest/jwt endpoint for the https://qaretail04.lucernex.com user (user is 'AlexisL' and firm name 'Webdriver').
Running Codegen
# Generate TypeScript types from GraphQL schema and queries
yarn codegenWhen to Run Codegen
Run the codegen command when:
- You add or modify GraphQL queries in
src/graphql/docs/*.graphql - The GraphQL schema on the backend has changed
- You need to update the generated types for your IDE
Generated Files
The following files are automatically generated (do not edit manually):
src/graphql/generated/types.ts- TypeScript type definitions for GraphQL types and operationssrc/graphql/generated/graphql-request.ts- Type-safe GraphQL client methods using graphql-request
To note: After generating you will need to format graphql-request.ts and types.ts with prettier. You will also need to add imports from types to graphql-request and remove all instances of ['input] from types.ts. It is annoying and I couldn't find a way to fix it with the codegen config.
Custom Scalar Mappings
The codegen is configured with the following scalar type mappings:
DateTime→stringDate→stringJSON→anyBigDecimal→numberLong→number
API Transition: REST/XML to GraphQL
This library is currently in transition from REST/XML endpoints to GraphQL. To handle overlapping model names during this transition, GraphQL types are exported under the GraphQL namespace.
Usage Examples
import { LucernexClient, GraphQL } from 'lucernex-client';
// REST/XML models (legacy)
import { Member, Project, Program } from 'lucernex-client';
// GraphQL models (use namespace to avoid conflicts)
const gqlProject: GraphQL.Project = await graphqlClient.getProject({ lxID: 123 });
const gqlMember: GraphQL.Member = await graphqlClient.getMember({ lxID: 456 });
// You can also import directly from the graphql path
import { LxGraphQLClient, Project as GQLProject } from 'lucernex-client/dist/graphql';GraphQL Client
const config = { baseUrl: 'https://your-instance.lucernex.com' };
const client = new GraphQL.LxGraphQLClient(config, 'your-auth-token');
// Query projects
const projects = await client.searchProjects({
fiql: 'projectName==*Store*',
limit: 10
});
// Get a specific member
const member = await client.getMember({ lxID: 123 });