GithubHelp home page GithubHelp logo

surveymonkey / graphql-ergonomock Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 5.0 548 KB

Automatic mocking of GraphQL queries

License: MIT License

JavaScript 0.53% TypeScript 99.47%
apollo apollo-client factory fixtures graphql mock mocking test testing

graphql-ergonomock's People

Contributors

dependabot[bot] avatar jfulse avatar joual avatar nikolaik avatar renovate[bot] avatar victor-guoyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

graphql-ergonomock's Issues

Fetching similar data with two different queries gives data undefined

Hello again,

I might be misunderstanding something here, but I have issues using ErgonoMockedProvider with several queries fetching the same object. Here's a minimal reproduction adapted from the example in the Readme:

import { render } from '@testing-library/react';
import { ErgonoMockedProvider } from 'graphql-ergonomock';
import { gql, useQuery } from '@apollo/client';

const schema = gql`
  type Shape {
    id: ID!
    returnInt: Int
    returnString: String
    returnBoolean: Boolean
  }

  type Query {
    getShape: Shape
  }
`;

const QUERY = gql`
  query MyQuery {
    getShape {
      id
      returnString
      returnBoolean
    }
  }
`;

const ANOTHER_QUERY = gql`
  query AnotherQuery {
    getShape {
      id
      returnInt
      returnBoolean
    }
  }
`;

const MyComponent = () => {
  const { loading, error, data } = useQuery(QUERY);
  const { loading: anotherLoading, error: anotherError, data: anotherData } = useQuery(ANOTHER_QUERY);
  if (loading || anotherLoading) return <p>Loading</p>;
  if (error || anotherError) return <p>Error</p>;

  return (
    <div>
      MyComponent.
      <div>String: {data.getShape.returnString}</div>
      <div>Boolean: {data.getShape.returnBoolean.toString()}</div>
      <div>Int: {anotherData.getShape.returnInt}</div>
    </div>
  );
};

test('MyComponent can render the query results.', async () => {
  const mocks = {
    MyQuery: {
      getShape: { returnString: 'John Doe' },
    },
    AnotherQuery: {
      getShape: { returnInt: 5 },
    },
  };
  const { findByText } = render(
    <ErgonoMockedProvider schema={schema} mocks={mocks}>
      <MyComponent />
    </ErgonoMockedProvider>,
  );
  expect(await findByText(/String: John Doe/)).toBeVisible();
  expect(await findByText(/Boolean: (true|false)/)).toBeVisible();
  expect(await findByText(/Int: 5/)).toBeVisible();
});

The test fails because data is undefined; if I remove the second query it works. The problem is the same if I don't supply any mocks.

Thanks!

Doesn't work with aliases.

This mocking library is fantastic (although it sadly looks abandoned?), non-the-less it's the only functional dynamic mocks library I've found that still works for the most part.

I did find that it has issues with queries that use aliases though.

Take this query which works just fine.

query SiteCounts {
    crm {
      sitesConnection(condition: { active: true }, first: 1) {
        totalCount
      }
    }
  }

I can mock it lik this:

const mocks = {
      SiteCounts: () => ({
        crm: {
          sitesConnection: {
            totalCount: 1,
          },
        },
      }),
    }

but if I add an alias to it like this:

query SiteCounts {
    crm {
      sites: sitesConnection {
        totalCount
      }
      activeSites: sitesConnection(condition: { active: true }, first: 1) {
        totalCount
      }
    }
  }

I can no longer mock it :(

const mocks = {
      SiteCounts: () => ({
        crm: {
          activeSites: {
            totalCount: 1,
          },
        },
      }),
    }

Doesn't work, and the original sitesConnection mock would override both parts of the query.

I haven't found any other issues, or any mention in the code of alias so I assume this was just never implemented.

But with the last update over 9 months ago, I'm guessing this project is dead? But I thought I'd create the ticket anyway just in case.

Using ergonomock-function with addTypename true

Hello and thanks for a great library!

I'm trying to use ergonomock() together with a MockedProvider that uses addTypename=true. This doesn't work out of the box because the results from ergonomock() only includes __typename if the query does, and we would like to avoid adding it to the latter manually.

Is there any chance of an addTypename option to ergonomock? If not do you have a suggestion for another solution?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency @testing-library/jest-dom to v6
  • chore(deps): update dependency jest-extended to v4
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency typescript to v5
  • chore(deps): update node orb to v5
  • chore(deps): update react monorepo to v18 (major) (@types/react, @types/react-dom, react, react-dom)
  • fix(deps): update dependency graphql to v16
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • node 4.7.0
npm
package.json
  • fast-json-stable-stringify ^2.1.0
  • graphql ^15.0.0
  • seedrandom ^3.0.5
  • @apollo/client 3.4.8
  • @testing-library/jest-dom 5.14.1
  • @testing-library/react 11.2.7
  • @types/react 17.0.18
  • @types/react-dom 17.0.9
  • @types/seedrandom 3.0.1
  • jest 26.6.3
  • jest-extended 0.11.5
  • prettier 2.3.2
  • react 17.0.2
  • react-dom 17.0.2
  • semantic-release 17.4.5
  • ts-jest 26.5.6
  • typescript 4.3.5

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: package.json
Error type: The renovate configuration file contains some invalid settings
Message: Invalid configuration option: author, Invalid configuration option: files, Invalid configuration option: keywords, Invalid configuration option: license, Invalid configuration option: main, Invalid configuration option: name, Invalid configuration option: packageRules[0].@apollo/client, Invalid configuration option: packageRules[0].@testing-library/jest-dom, Invalid configuration option: packageRules[0].@testing-library/react, Invalid configuration option: packageRules[0].@types/react, Invalid configuration option: packageRules[0].@types/react-dom, Invalid configuration option: packageRules[0].@types/seedrandom, Invalid configuration option: packageRules[0].jest, Invalid configuration option: packageRules[0].jest-extended, Invalid configuration option: packageRules[0].prettier, Invalid configuration option: packageRules[0].react, Invalid configuration option: packageRules[0].react-dom, Invalid configuration option: packageRules[0].semantic-release, Invalid configuration option: packageRules[0].ts-jest, Invalid configuration option: packageRules[0].typescript, Invalid configuration option: packageRules[1].fast-json-stable-stringify, Invalid configuration option: packageRules[1].graphql, Invalid configuration option: packageRules[1].graphql-tools, Invalid configuration option: packageRules[1].seedrandom, Invalid configuration option: renovate, Invalid configuration option: scripts, Invalid configuration option: version

Is this under active development

Hey there 👋 I've been investigating using this package for a project I work on. I noticed the last commit was a while back so was wondering if this is still under use/development?
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.