Skip to content
This repository has been archived by the owner on Jul 4, 2020. It is now read-only.

RequestError when using this package #3

Closed
Dastari opened this issue Jan 26, 2019 · 4 comments
Closed

RequestError when using this package #3

Dastari opened this issue Jan 26, 2019 · 4 comments

Comments

@Dastari
Copy link

Dastari commented Jan 26, 2019

I get the following error whenever I use any of the load functions:

error: { RequestError: Requests can only be made in the LoggedIn state, not the SentClientRequest state at Request.tds.Request.err [as userCallback] (C:\Dev\gema\api\node_modules\mssql\lib\tedious.js:614:19) at Request._this.callback (C:\Dev\gema\api\node_modules\tedious\lib\request.js:61:27) at Connection.makeRequest (C:\Dev\gema\api\node_modules\tedious\lib\connection.js:1606:17) at Connection.execSql (C:\Dev\gema\api\node_modules\tedious\lib\connection.js:1369:12) at Immediate.parent.acquire [as _onImmediate] (C:\Dev\gema\api\node_modules\mssql\lib\tedious.js:838:63) at runCallback (timers.js:697:11) at tryOnImmediate (timers.js:667:5) at processImmediate (timers.js:649:5) at process.topLevelDomainCallback (domain.js:121:23) code: 'EINVALIDSTATE', number: 'EINVALIDSTATE', state: undefined, originalError: { RequestError: Requests can only be made in the LoggedIn state, not the SentClientRequest state at RequestError (C:\Dev\gema\api\node_modules\tedious\lib\errors.js:34:12) at Connection.makeRequest (C:\Dev\gema\api\node_modules\tedious\lib\connection.js:1606:26) at Connection.execSql (C:\Dev\gema\api\node_modules\tedious\lib\connection.js:1369:12) at Immediate.parent.acquire [as _onImmediate] (C:\Dev\gema\api\node_modules\mssql\lib\tedious.js:838:63) at runCallback (timers.js:697:11) at tryOnImmediate (timers.js:667:5) at processImmediate (timers.js:649:5) at process.topLevelDomainCallback (domain.js:121:23) message: 'Requests can only be made in the LoggedIn state, not the SentClientRequest state', code: 'EINVALIDSTATE' }, name: 'RequestError', precedingErrors: [] } query: COMMIT

index.js

import "reflect-metadata";
import { ApolloServer } from "apollo-server-express";
import * as Express from "express";
import { createConnection } from "typeorm";
import { createSchema } from "./utils/createSchema";

import { GraphQLDatabaseLoader } from "typeorm-loader";

const main = async () => {
  const schema = await createSchema();
  const connection = await createConnection(/* loaded from ormconfig.json */);
  const loader = new GraphQLDatabaseLoader(connection);

  const apolloServer = new ApolloServer({
    context: ({ request, response }: any) => ({
      request,
      response,
      loader
    }),
    schema
  });

  const app = Express();

  apolloServer.applyMiddleware({ app });

  app.listen(4000, () => {
    console.log("Server Started on http://localhost:4000/graphql");
  });
};
main();

Then in my Entity:

  @Field(() => [Job])
  async AssignedJobs(
    @Ctx() { loader }: BaseContext,
  ): Promise<Job[]> {
    return loader.loadMany(Job, { NameNo: this.CardNo }) as Promise<
      Job[]
    >;
  }

Any thoughts? Is this a unique issue with using the mssql driver?

@Dastari Dastari changed the title RequestError when using this pacakge RequestError when using this package Jan 26, 2019
@voodooattack
Copy link
Contributor

Hi! Does the issue persist if you load the data using TypeORM directly? It sounds more like a TypeORM connection issue.

This could be related, by the way: tediousjs/tedious#458

@Dastari
Copy link
Author

Dastari commented Jan 27, 2019

Hi! Does the issue persist if you load the data using TypeORM directly? It sounds more like a TypeORM connection issue.

This could be related, by the way: tediousjs/tedious#458

It does work loading data using TypeORM directly.

I think the issue may be related to TypeORM still using the connection when using the loader directly in the entity @field. If I move the loader into a @FieldResolver in the @resolver the issue goes away.

@voodooattack
Copy link
Contributor

What happens if you do something like this?

  @Field(() => [Job])
  async AssignedJobs(
    @Ctx() { loader }: BaseContext,
  ): Promise<Job[]> {
    return new Promise((resolve, reject) => {
        setTimeout(() => loader.loadMany(Job, { NameNo: this.CardNo }).then(resolve, reject), 0); 
    });
  }

@voodooattack
Copy link
Contributor

Assuming this resolved because there was not response.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants