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

Subscription and service level resolver #72

Closed
palpinter opened this issue Apr 22, 2020 · 7 comments · Fixed by #73
Closed

Subscription and service level resolver #72

palpinter opened this issue Apr 22, 2020 · 7 comments · Fixed by #73

Comments

@palpinter
Copy link

palpinter commented Apr 22, 2020

My problem is when I define resolvers in settings with graphql, resolvers works as expected when I call a query. But when I call subscriptions resolvers do not work.

This is the example definition:

graphql: {
    type: [
        Employee,
        EmployeeList,
        Address,
        Phone,
        Email,
        AddressInput,
        PhoneInput,
        EmailInput,
    ],
    resolvers: {
        Employee: {
            gender: {
                action: "genders.read",
                rootParams: {
                    gender: "code",
                },
            },
            maritalStatus: {
                action: "maritalStatuses.read",
                rootParams: {
                    maritalStatus: "code",
                },
            },
        },
        Address: {
            streetType: {
                action: "streetTypes.read",
                rootParams: {
                    streetType: "code",
                },
            },
        },
    },
},

Do I need to define other resolvers for subscriptions? I haven't found any example of using resolvers with subscriptions.

This works in the http://localhost:3000/graphql:

query {
  employee(code: "0000000017") {
    code
    gender {
      code
    }
  }
}

But this doesn't:

subscriptions {
  employee(code: "0000000017") {
    code
    gender {
      code
    }
  }
}

Sorry but I don't understand.
Thx

@shawnmcknight
Copy link
Member

Without seeing the rest of your service definition its hard to figure out what's going on here. Can you make a repo with your services in it to give the full picture?

@palpinter
Copy link
Author

Hi,

Thanks for your fast answer.
This is the repo:
https://github.com/palpinter/moleculer-apollo-demo

The services/employees.service.js file contains the relevant code.

@palpinter palpinter reopened this Apr 24, 2020
@palpinter
Copy link
Author

Sorry for faulty closing. The question is open.

@palpinter
Copy link
Author

palpinter commented Apr 25, 2020

Hi,

I dont understand well your code, but I have changed the service.js line 313 from:

this.broker.call(actionName, { ...params, payload }, ctx),

to

this.broker.call(actionName, params)

So it is works now in playground.
But I not able to use it from React Apollo client on websocket link. It drops error:

{ "errors": [ { "message": "Cannot read property 'call' of undefined", "locations": [ { "line": 10, "column": 7 } ], "path": [ "employee", "gender" ], "extensions": { "code": "INTERNAL_SERVER_ERROR" } } ], "data": { "employee": null } }

It means for me, that the resolver doesn't work.
Thx
P.

@icebob
Copy link
Member

icebob commented Apr 25, 2020

@Hugome maybe could you help with it?

@Hugome
Copy link
Collaborator

Hugome commented Apr 25, 2020

The path in the error is "employee.gender", which mean that the resolution of this field has an error.

{
  "errors": [
    {
      "message": "Cannot read property 'call' of undefined",
      "locations": [
        {
          "line": 4,
          "column": 5
        }
      ],
      "path": [
        "employee",
        "gender"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR"
      }
    }
  ],
  "data": {
    "employee": null
  }
}

With a little of digging the context.ctx in src/service.js#200 is undefined, because it's not defined in case of a ws connection src/service.js#576.
I've open a PR to propose a solution for this case : #73

@palpinter
Copy link
Author

Thank you very much @Hugome!
It works with my change:
from

this.broker.call(actionName, { ...params, payload }, ctx),

to

this.broker.call(actionName, params)

But not without this.

Once more thank you.
P.

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 a pull request may close this issue.

4 participants