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

code always INTERNAL_SERVER_ERROR when using mergeSchemas #1037

Closed
ph55 opened this issue Dec 27, 2018 · 5 comments
Closed

code always INTERNAL_SERVER_ERROR when using mergeSchemas #1037

ph55 opened this issue Dec 27, 2018 · 5 comments
Assignees
Labels

Comments

@ph55
Copy link

ph55 commented Dec 27, 2018

Seems that #925 not completely fixed.
I'm using graphql-middleware and when throwing error the code is always INTERNAL_SERVER_ERROR.

Reproduction:

import { applyMiddleware } from 'graphql-middleware';
import { mergeSchemas } from 'graphql-tools';
import { AuthenticationError } from 'apollo-server-errors';

// ...
const errored = () => {
    throw new AuthenticationError('Not allowed');
};

const middleware = {
    User: {
      phone: errored
    }
};
//...
schema = applyMiddleware(schema, middleware);
schema = mergeSchemas({ schemas: [schema] });
// ...

Result with trace:

{
  "errors": [
    {
      "message": "Not allowed",
      "locations": [
        {
          "line": 5,
          "column": 5
        }
      ],
      "path": [
        "user",
        "phone"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Not allowed",
            "    at defaultMergedResolver (/app/node_modules/graphql-tools/src/stitching/defaultMergedResolver.ts:18:24)",
            "    at field.resolve (/app/node_modules/graphql-tools/src/stitching/mergeSchemas.ts:263:16)",
            "    at field.resolve (/app/node_modules/graphql-extensions/src/index.ts:267:18)",
            "    at resolveFieldValueOrError (/app/node_modules/graphql/execution/execute.js:479:18)",
            "    at resolveField (/app/node_modules/graphql/execution/execute.js:446:16)",
            "    at executeFields (/app/node_modules/graphql/execution/execute.js:293:18)",
            "    at collectAndExecuteSubfields (/app/node_modules/graphql/execution/execute.js:717:10)",
            "    at completeObjectValue (/app/node_modules/graphql/execution/execute.js:707:10)",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:598:12)",
            "    at /app/node_modules/graphql/execution/execute.js:500:16"
          ]
        }
      }
    }
  ],
  "data": {
    "user": {
      "id": 1,
      "email": "a@b.kek",
      "phone": null
    }
  }
}

After removing mergeSchemas , error code returned as expected:

{
  "errors": [
    {
      "message": "Not allowed",
      "locations": [
        {
          "line": 5,
          "column": 5
        }
      ],
      "path": [
        "user",
        "phone"
      ],
      "extensions": {
        "code": "UNAUTHENTICATED",
        "exception": {
          "stacktrace": [
            "AuthenticationError: Not allowed",
            "    at errored (/app/src/@core/graphql/graphql-middleware/graphql-middleware.service.ts:12:13)",
            "    at /app/node_modules/graphql-middleware/src/applicator.ts:32:5",
            "    at field.resolve (/app/node_modules/graphql-extensions/src/index.ts:267:18)",
            "    at resolveFieldValueOrError (/app/node_modules/graphql/execution/execute.js:479:18)",
            "    at resolveField (/app/node_modules/graphql/execution/execute.js:446:16)",
            "    at executeFields (/app/node_modules/graphql/execution/execute.js:293:18)",
            "    at collectAndExecuteSubfields (/app/node_modules/graphql/execution/execute.js:717:10)",
            "    at completeObjectValue (/app/node_modules/graphql/execution/execute.js:707:10)",
            "    at completeValue (/app/node_modules/graphql/execution/execute.js:598:12)",
            "    at /app/node_modules/graphql/execution/execute.js:500:16"
          ]
        }
      }
    }
  ],
  "data": {
    "user": {
      "id": 1,
      "email": "a@b.kek",
      "phone": null
    }
  }
}
@arc-008
Copy link

arc-008 commented Jan 9, 2019

@ph55 I had similar issue while merging remote schemas. I have imported "extractExtensionDefinitions" from "graphql-tools" (4.0.3) to resolve. Not sure about your scenario though.

@asoet
Copy link

asoet commented Jan 15, 2019

@8arcturus how/where did you use extractExtensionDefinitions? Only importing "extractExtensionDefinitions" doesn't have any effect. No sure how to use it.

My problem extensions are removed when there are multiple errors. They are combined to one error. It's probably an extensions to this problem

@hwillson
Copy link
Contributor

hwillson commented Mar 7, 2019

Here's a runnable reproduction that demonstrates this issue:
https://github.com/hwillson/graphql-tools-stitching-errors

I'm working on a fix now, and will have it ready shortly.

yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Jun 12, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Jun 18, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Sep 22, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Sep 22, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Sep 22, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
@gajus
Copy link

gajus commented Sep 23, 2019

Is there a workaround for this at the moment?

yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Oct 3, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Oct 25, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Oct 25, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Nov 4, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Dec 31, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Dec 31, 2019
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Jan 8, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Jan 21, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Feb 27, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Mar 26, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
yaacovCR pushed a commit to yaacovCR/graphql-tools-fork that referenced this issue Mar 26, 2020
Use new relocatedError function to update the original GraphQLErrors
with the new path. Addresses ardatan#743, ardatan#1037, ardatan#1046,
apollographql/apollo-server#1582.
@yaacovCR
Copy link
Collaborator

Rolled into #1306

@yaacovCR yaacovCR mentioned this issue Mar 29, 2020
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants