Skip to content

GraphQL-PPX Compatibility Validation

Objective

Validate graphql-ppx compatibility with Melange 5.0 and establish type-safe GraphQL query generation pipeline.

Background

graphql-ppx (v1.2.2, last updated 2021) needs testing with Melange 5.0. If incompatible, we'll evaluate alternatives like ppx_graphql.

Tasks

  • Install graphql_ppx from OPAM
  • Create test queries with graphql-ppx
  • Verify ppxlib version compatibility
  • Test with exported PostGraphile schema
  • Configure dune for PPX preprocessing
  • Validate generated types with Melange
  • Document any workarounds needed
  • Create fallback plan if incompatible

Test Implementation

(* test/GraphQLTest.re *)
module GetUser = [%graphql
  {|
    query GetUser($id: ID\!) {
      user(id: $id) {
        id
        email
        name
      }
    }
  |}
];

let testQuery = () => {
  let query = GetUser.make(~id="1", ());
  Js.log(query##variables);
};

Dune Configuration

(library
 (name graphql_test)
 (libraries melange.js graphql_ppx melange_apollo)
 (modes melange)
 (preprocess (pps graphql_ppx melange.ppx)))

Acceptance Criteria

  • PPX processes GraphQL queries without errors
  • Generated types work with Melange
  • Can use types with Apollo bindings
  • Schema file loading works
  • Variables properly typed
  • Fragments supported

Alternative Approaches

Option A: ppx_graphql

opam install ppx_graphql

Option B: Manual Types

(* If PPX fails, use manual approach *)
type userQuery = {
  id: string,
  email: string,
  name: option(string),
};

let query = {|
  query GetUser($id: ID\!) {
    user(id: $id) { id email name }
  }
|};

Option C: Generate Types from Schema

# Use graphql-codegen with custom templates
npm run codegen:types

Version Compatibility Matrix

Component Required Current Status
Melange 5.0+ 5.0
ppxlib <0.36.0 ? Test
graphql_ppx 1.2.2 1.2.2 Test
OCaml 4.06+ 5.3

Testing Strategy

  1. Simple query test
  2. Query with variables
  3. Mutation test
  4. Fragment test
  5. Union types test
  6. Interface types test

Priority: 🟡 High

Can work around if needed, but impacts DX significantly.

Estimated Effort: 1-2 days

Risk Mitigation

If graphql-ppx fails:

  1. Try ppx_graphql (2 hours)
  2. Use manual types (4 hours)
  3. Build codegen solution (1 day)
  4. Use PostGraphile client (2 hours)

Dependencies

  • #38 PostGraphile API (need schema.graphql)
  • #36 Apollo bindings (to test integration)

CI Validation

  • PPX preprocessing succeeds
  • Type checking passes
  • Generated code compiles