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

additionalResolvers doesn't work #2868

Closed
jangot opened this issue Sep 28, 2021 · 3 comments
Closed

additionalResolvers doesn't work #2868

jangot opened this issue Sep 28, 2021 · 3 comments

Comments

@jangot
Copy link

jangot commented Sep 28, 2021

Describe the bug

I just started to read documentation. And when I tried to use additionalResolvers I got a problem.
Here there is an example how to add custom field to scheme.
To Reproduce
I created .meshrc.yaml

sources:
  - name: Wiki
    handler:
      openapi:
        source: https://api.apis.guru/v2/specs/wikimedia.org/1.0.0/swagger.yaml

additionalTypeDefs: |
  extend type Query {
    viewsInPastMonth: Float!
  }
additionalResolvers:
  - ./src/mesh/additional-resolvers.js

and this is the resolver

const moment = require('moment');

const resolvers = {
    Query: {
        viewsInPastMonth: async (root, args, context, info) => {
            const params = {
                root,
                args: {
                    access: 'all-access',
                    agent: 'user',
                    end: moment().format('YYYYMMDDHH'),
                    start: moment().startOf('month')
                        .subtract(1, 'month')
                        .format('YYYYMMDDHH'),
                    project: 'en.wikipedia.org',
                    granularity: 'monthly',
                },
                context,
                info,
                selectionSet: /* GraphQL */`
          {
            views
          }
        `
            }

            try {
                const data = await context.Wiki.Query.getMetricsPageviewsAggregateProjectAccessAgentGranularityStartEnd(params);
                console.log(data);
                if (!data) {
                    return 0;
                }
                const items = (!!data && !!data.items) ? data.items : [];

                if (!items || items.length === 0) {
                    return 0;
                }

                return items[0].views;
            } catch (err) {
                console.log(err)
                return 0;
            }

        },
    },
};

module.exports = {
    resolvers
}

Expected behavior

I expected to get count of views for first item. But in console I see that data is null.
I thought I wrote selectionSet wrong but I tried different values but have no results.

Environment:

  • iOS
    "dependencies": {
    "@graphql-mesh/cli": "^0.39.0",
    "@graphql-mesh/openapi": "^0.18.14",
    "graphql": "^15.5.3",
    "moment": "^2.29.1"
    }
    node: 14

Additional context

@fr3fou
Copy link

fr3fou commented May 10, 2022

any news? I've been dealing with the same issue

@jamiewinder
Copy link

Shouldn't resolvers be the default export? i.e. module.exports = resolvers; ?

@ardatan
Copy link
Owner

ardatan commented Jul 20, 2022

I think this has been fixed in the latest versions. Feel free to create a new issue with a clear reproduction on CodeSandbox or StackBlitz. Thanks!

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

No branches or pull requests

4 participants