4

I have two GraphQL schemas that define two different Types User which are in a one-to-one relationship. Each of them implements a set of arguments (filter, condition, ...) that are used for filtering for example.

// analyticsSchema
type User {
  id: String!
  actions: Int
}

// metadataSchema
type User {
  id: String!
  age: Int
}

These types are merged bi-directionally:

const gatewaySchema = stitchSchemas({
  subschemas: [
    {
      schema: analyticsSchema,
      merge: {
        User: {
          fieldName: 'analyticsById',
          selectionSet: '{ id }',
          args: originalObject => ({ id: originalObject.id }),
        },
      },
    },
    {
      schema: metadataSchema,
      merge: {
        User: {
          fieldName: 'metadataById',
          selectionSet: '{ id }',
          args: originalObject => ({ id: originalObject.id }),
        },
      },
    },
  ],
  mergeTypes: true, 
});

With this implementation, I do not have access to all fields for filtering:

// What I can do 
query ExampleQuery {
  allUsers(filter: { actions: { greaterThan: 10 }}) {
    edges {
      node {
        id
        actions
        age
      }
    }
  }
}

// What I would like to do
query ExampleQuery {
  allUsers(filter: {actions: {greaterThan: 10}, age: {lessThan: 35}}) {
    edges {
      node {
        id
        actions
        age
      }
    }
  }
}

> Problem: Field "age" is not defined by type "UserFilter".

My question is, is it possible to expose all filtering arguments to the resulting merged type? Or maybe I'm going the wrong way?

N.B: both GraphQL endpoints rely on postgraphile and we're using the postgraphile-plugin-connection-filter plugin if that matters.

danronmoon
  • 3,814
  • 5
  • 34
  • 56
kluu
  • 2,848
  • 3
  • 15
  • 35
  • Did you try delegating request from one query to another? Is there any issue with using a single Schema for both `Users` and initialize non-used datatype will `'NULL` value? – Haris Qurashi Sep 15 '21 at 11:26

0 Answers0