npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@metaliq/integration

v1.0.0-beta.134

Published

MetaliQ integration policy

Downloads

279

Readme

@metaliq/integration

Overview

MetaliQ's core integration policy is based on the GraphQL standard for schema-based APIs. It is designed to support a number of integration strategies:

  • Connect to an associated back-end - possibly built using @metaliq/graphql-server
  • Connect to a third-party (public or partner) API published using GraphQL
  • Connect to a system component or service that has a GraphQL capability, such as:
    • Supabase
    • FaunaDB
    • Neo4J
    • ...etc.

For non-GraphQL integration needs, there are various options:

  • Direct integration code within application processes (e.g. fetch from a REST URL and process the results)
  • Wrap the integration in a cloud function and provide a client facade with @metaliq/graphql-server

The latter is a good option when accessing commercial APIs with secure keys and credentials, when wishing to maintain secure cross-service access logs, or when needing to access and include sensitive intermediate data. These types of facades can proxy and aggregate 3rd party services, which themselves might be GraphQL or another format such as REST or SOAP.

Capabilities

This module provides a number of capabilities around developing GraphQL clients - i.e. applications that connect to GraphQL API services. For more information on building GraphQL API service providers themselves, see the documentation for the @metaliq/graphql-server publication target module. That target in turn uses several of the capabilities provided by this integration policy, including generation of suitable types for schema-based service resolvers.

Updating a local GraphQL Schema

In this case, where you're connecting to and developing against an external schema, there are various ways to obtain the schema for inclusion in your local project, but MetaliQ makes this easy with a convenient wrapper around the get-graphql-schema utility. The integration policy makes this available via the MetaliQ CLI as follows:

metaliq get-graphql-schema https://my-service/api gql/schema.gql

You would typically include this in the scripts section in your package.json file.

MetaliQ solutions that connect to a single service often use the conventional schema location of gql/schema.gql so it will be set as default if not specified.

metaliq get-graphql-schema https://my-service/api

Generate TypeScript Code

Having authored or obtained a local copy of the GraphQL schema, MetaliQ will then assist you in generating a set of TypeScript source files within the src/gen folder location. This location is conventionally ignored from version control using .gitignore, as it includes source code which is itself generated from other sources (in this case the GraphQL schema) and thus can always be re-generated. These files are thus not truly original solution source code, but they need to live within the src folder for TypeScript compilation reasons.

  • Provide MetaModel terms to configure one or multiple GraphQL API connections
    • Service URL
    • Local schema location
    • Location of a concrete "operations" file
  • Provide a facility to update the local schema definition from a remote API
  • Support client-side GraphQL operation calls with multi-stage error handling
  • Generate client-side TypeScript code from a GraphQL schema
    • Types matching schema types and operations
    • Resolvers matching schema operations and types (the basis for server-side MetaModels)
    • Functions providing a type-safe facade to all concrete operations defined within a local GraphQL file
  • Provide the MetaModel functions $.op that links a GraphQL operation directly to the Meta graph

Taken together, it means you can go straight from some GraphQL like this:

type Customer {
	id: String
	firstName: String
	lastName: String
}

input CustomerIn {
  id: String
	firstName: String
	lastName: String
}

query {
	fetchCustomers (search: String): Customer[]
}

mutation {
	updateCustomer (customer: CustomerIn): Customer
}

and some concrete operations like this:

query searchCustomers ($search: String) {
	fetchCustomers (search: $search) {
		id
		firstName
		lastName
	}
}

mutation saveCustomer ($customer: CustomerIn) {
	updateCustomer (customer: $customer): {
		id
		firstName
		lastName
	}
} 

to hooking up processes with type-safe code like this, without further boilerplate:

$.op(searchCustomersQuery, { search: app.searchString })

The above code could be attached to a button click, for example, and would handle all aspects of calling the GraphQL query with the provided parameter, handling various types of error appropriately, allocating the result back into the local data and meta graph and performing any configured application review (such as updating a reactive front-end if used with the @metaliq/presentation policy). Similarly, the following code could be attached to a Save button:

$.op(saveCustomerMutation)

As well as saving the customer (and integrating any changes made by the service itself), this saves a lot of techno-boilerplate code, and emphasises the organisational intent.

If you need greater control than provided by gUp, you can use the type-safe operations facade directly and handle the response data yourself, whilst still getting the benefit of a type-safe API with error handling and automatic input type marshalling.