Skip to content

Implement aliasing for fields #26

@krisgrint

Description

@krisgrint

Relates to #11 and the discussion in PR #22

Aliasing of fields in forwarded queries does not appear to be supported out of the box.

Consider the following addition to the test cases in test/proxy.test.js. The first test cases passes, but the second two fail:

{
    name: 'should federate a basic service with queries with aliases on fields',
    services: [
      {
        schema: dedent`
        type Query {
          me: User
        }
        type User {
          id: ID!
          name: String!
          address: String
        }
      `,
        resolvers: {
          Query: {
            me: () => db.users[1]
          },
          User: {
            address: () => 'Banbury'
          }
        }
      }
    ],
    queries: [
      {
        query: '{ me { userId: id, name } }',
        expected: {
          me: {
            userId: '1', // returns the correct aliased field
            name: 'Jimmy'
          }
        }
      },
      {
        query: '{ me { id, firstName: name } }',
        expected: {
          me: {
            userId: '1',
            firstName: 'Jimmy' // returns null for entire me object
          }
        }
      },
      {
        query: '{ me { id, location: address } }',
        expected: {
          me: {
            id: '1',
            location: 'Banbury' // returns null for location
          }
        }
      }
    ]
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions