Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make replaceExtensions work with inheritTypeDefs #1645

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kamilkisiela
Copy link
Collaborator

@kamilkisiela kamilkisiela commented Apr 12, 2021

Related #1634

@theguild-bot
Copy link

The latest changes of this PR are available as alpha in npm (based on the declared changesets):

@maapteh
Copy link
Contributor

maapteh commented Apr 13, 2021

i tweaked my test to be more real about list having multiple products below, else its a weird testcase :)

@kamilkisiela I validated now the extension on other modules types are working with 'replaceExtensions' to true, the option now only merges extension on Query/Mutation/Subscription.

Do you need to alter the docs at https://www.graphql-modules.com/docs/essentials/testing#turning-type-extensions-into-definitions ? I cant imagine you dont want to flatten eachother typings but since it was an option before this PR im not so sure :)

@maapteh
Copy link
Contributor

maapteh commented Apr 13, 2021

my testcase:

import "reflect-metadata";
import { createModule, testkit, gql } from "graphql-modules";

describe("testModule", () => {
  const ListModule = createModule({
    id: "list",
    typeDefs: gql`
      extend type Query {
        list: List!
      }
      type List {
        id: ID!
        title: String!
      }
    `,
    resolvers: {
      Query: {
        list() {
          return {
            id: "123-456-789",
            title: "foo"
          };
        }
      }
    }
  });

  const ProductModule = createModule({
    id: "product",
    typeDefs: gql`
      extend type Query {
        product: Product!
      }
      type Product {
        id: ID!
      }
      # this module extends on list
      extend type List {
        products: [Product!]
      }
    `,
    resolvers: {
      Query: {
        product() {
          return {
            id: "42"
          };
        }
      },
      List: {
        products: () => {
          return [
            {
              id: "42"
            }
          ];
        }
      }
    }
  });

  test("should not throw error", () => {
    expect(() =>
      testkit.testModule(ProductModule, {
        replaceExtensions: true,
        inheritTypeDefs: [ListModule]
      })
    ).not.toThrow();
  });

  test("product extends list correctly while testing product module", async () => {
    const app = testkit.testModule(ProductModule, {
      inheritTypeDefs: [ListModule],
      replaceExtensions: true
    });

    const result = await testkit.execute(app, {
      document: gql`
        query product {
          product {
            id
          }
        }
      `
    });

    expect(result.data.product.id).toBe("42");
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants