Registry / communication / purescript-graphql-client

purescript-graphql-client

JSON →
library10.1.1jsnpmunverified

A type-safe GraphQL client for PureScript (version 10.1.1) that ensures GraphQL queries, arguments, and responses are type-checked against a PureScript representation of the schema. It includes codegen tools to generate PureScript types from a GraphQL schema, reducing manual effort and errors. Compared to alternatives like purescript-graphql-fundeps, this library provides a more ergonomic DSL for constructing queries and supports both Apollo and non-Apollo server features. Release cadence is irregular; last release was 2021.

npm install purescript-graphql-client
INSTALL
IMPORT
SIG · PURESCRIPT-GRAPHQL
P
purescript-graphql-client
communicationjavascriptv10.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

query_
import GraphQL.Client.Query (query_)
import GraphQL.Client.Types (query_)
query_ is exported from GraphQL.Client.Query, not Types.
GqlQuery
import GraphQL.Client.Types (class GqlQuery)
import GraphQL.Client (GqlQuery)
GqlQuery is a typeclass, imported from GraphQL.Client.Types.
(=>>)
import GraphQL.Client.Args ((=>>))
import Data.Functor ((=>>))
The graphql-client library defines its own (=>>) operator; importing from Data.Functor will cause conflicts.

Shows a complete minimal application making a typesafe GraphQL query with custom schema definition.

module Main where import Prelude import Data.Argonaut.Decode (class DecodeJson) import Effect (Effect) import Effect.Aff (launchAff_) import Effect.Class.Console (logShow) import GraphQL.Client.Args ((=>>)) import GraphQL.Client.Query (query_) import GraphQL.Client.Types (class GqlQuery, Nil') import Type.Proxy (Proxy(..)) main :: Effect Unit main = launchAff_ do { widgets } <- queryGql "Widget names" { widgets: { id: 1 } =>> { name } } logShow $ map _.name widgets queryGql :: forall query returns. GqlQuery Nil' OpQuery Schema query returns => DecodeJson returns => String -> query -> Aff returns queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Schema) type Schema = { prop :: String, widgets :: { id :: Int } -> Array Widget } type Widget = { name :: String, id :: Int } name :: Proxy "name" name = Proxy
Debug
Known issues
gotchaOperator (=>>) conflicts with Data.Functor's (=>>). Must import from GraphQL.Client.Args.
fix
Use 'import GraphQL.Client.Args ((=>>))' and avoid imports from Data.Functor.
affects: >=1.0
gotchaThe query type must be a record of fields matching the schema; missing fields cause compile errors but runtime errors if schema is out of sync.
fix
Use the codegen tool to keep PureScript schema in sync with GraphQL schema.
affects: >=5.0
deprecatedThe server-side module GraphQL.Client.Server is deprecated; use browser-based HTTP instead.
fix
Migrate to using fetch or other HTTP library; see docs for browser example.
affects: >=9.0
breakingIn v7.0 the mutation API changed: mutations now require a mutation wrapper instead of using query_.
fix
Use 'mutation_' or 'mutationGql' functions from GraphQL.Client.Mutation.
affects: >=7.0 <8.0
Errors
Common errors & fixes
Could not match inferred type Int with type Proxy ("name") while checking that expression # has type Proxy ("name")
Using a string literal instead of a Proxy symbol for field names in query.
fix
Use Proxy like `name :: Proxy "name"` and pass `name` in the query, not the string `"name"`.
No type class instance was found for GraphQL.Client.Types.GqlQuery
The query type does not match the schema type, or missing schema type annotation.
fix
Ensure the query record structure matches the schema and the schema type is provided as a Proxy to query_.
Upgrade
Version history
10.1.1latest on npm
Audit
Dependencies
purescript-argonaut-corerequiredJSON encoding/decoding
purescript-argonaut-codecsrequiredJSON codec instances
purescript-affrequiredAsynchronous effect handling
purescript-httpurifyrequiredHTTP client for browser/server
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
purescript-graphql-client — npm install purescript-graphql-client · libregistry