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

What server has to return to make fresh work? #51

Closed
vytautas-pranskunas- opened this issue Aug 20, 2021 · 4 comments
Closed

What server has to return to make fresh work? #51

vytautas-pranskunas- opened this issue Aug 20, 2021 · 4 comments
Assignees

Comments

@vytautas-pranskunas-
Copy link
Contributor

Hi, I have a situation when i was sure that this peace is working. However today i have realized that it is not. I checked your example and implement things similarly. However I am not sure what server has to return to make it work. Now from server I am returning pure gql error (when calling via postman)

{
    "errors": [
        {
            "message": "Context creation failed: Authentication token is invalid, please log in",
            "extensions": {
                "code": "UNAUTHENTICATED",
                "exception": {
                    "stacktrace": [
                        "AuthenticationError: Context creation failed: Authentication token is invalid, please log in",
                        "    at ApolloServer.context (D:\\SenioAssist\\senioassit-api\\src\\main.ts:71:23)",
                        "    at runMicrotasks (<anonymous>)",
                        "    at processTicksAndRejections (internal/process/task_queues.js:93:5)"
                    ]
                }
            }
        }
    ]
}

And i am sure that previously this error was caught by fresh plugin however now it is not. And i see this error in console

Caught error: OperationException(linkException: ServerException(originalException: null, parsedResponse: Response(data: null, errors: [GraphQLError(message: Context creation failed: Authentication token is invalid, please log in, locations: null, path: null, extensions: {code: UNAUTHENTICATED, exception: {stacktrace: [AuthenticationError: Context creation failed: Authentication token is invalid, please log in,     at ApolloServer.context (D:\SenioAssist\senioassit-api\src\main.ts:71:23),     at runMicrotasks (<anonymous>),     at processTicksAndRejections (internal/process/task_queues.js:93:5)]}})], context: Context({ResponseExtensions: Instance of 'ResponseExtensions'}))), graphqlErrors: [])

I am not sure why server error is not wrapped into linkException rather than graphqlErrors.

Maybe I am returning it incorrect from server? maybe it is because when I am throwing AuthenticationError from Apollo server it gives 400 (bad request) instead of 200 along with error mentioned above?

@vytautas-pranskunas-
Copy link
Contributor Author

After some testing I see that problem is 400 status code.
Just do not understand how your code works because if i thorw AuthenticationError in context create from ApolloServer it returns 400.

apollographql/apollo-server#1709

@felangel felangel self-assigned this Aug 20, 2021
@felangel
Copy link
Owner

Hi @vytautas-pranskunas- 👋
Thanks for opening an issue!

Are you able to provide a link to a minimal reproduction sample? I’m happy to take a closer look at the specific issue you’re encountering 👍

@vytautas-pranskunas-
Copy link
Contributor Author

I can give you code snippets:

const apolloServer = new ApolloServer({
        schema,
        context: async ({ req, connection }: { req: any; connection: any }) => {
            if (connection) {
                return connection.context;
            }
            throw new AuthenticationError('Authentication token is invalid, please log in');
            return {  } ;
        },
       
    });

rest you can take from https://www.apollographql.com/docs/apollo-server/getting-started/

@felangel
Copy link
Owner

Closing this for now since this is quite old but if this is still an issue please let me know and I'm happy to take a closer look.

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

2 participants