neo4j / graphql

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations.
https://neo4j.com/docs/graphql-manual/current/
Apache License 2.0
508 stars 149 forks source link

apollo server is slow when more type definitions #2555

Closed Hashdhi closed 1 year ago

Hashdhi commented 1 year ago

Env Details : "@neo4j/graphql": "^3.12.0", "@neo4j/introspector": "^1.0.2", "apollo-server": "^3.11.1", "dotenv": "^16.0.3", "graphql": "^16.6.0", "neo4j-driver": "^4.4.3" OS : Windows10

We have 201 type definitions and 105 interface definitions in graphql file. neo4j graphql generates SDL file of size around 26 MB ( around 8002 type def in SDL )

Problem is , For simple query takes around 3-5 minutes to get the response . Below is code snippet to start server const server = new ApolloServer({ schema: schema, introspection: true, playground: true, });

however, if we work with less number(~20-25) of type definitions then it works as expected .its clear that when type definition is more then its not working. Is there any size limit or restriction on the number of type definitions in graphql ? are we missing any configuration ?

Tried adding only query and excluded mutation but still behaviour hasnt changed 'i.e query takes long time to respond

mjfwebb commented 1 year ago

Hi @Hashdhi! While an increase in the number of type definitions may correlate to a slight performance hit, generally speaking just having a larger amount of type definitions shouldn't be the direct cause for relatively simple queries to take so long.

If possible, can you provide us with a bit more information so we might try to reproduce this ourselves? It's possible you've encountered a genuine issue that we need to address.

Alternatively, it could be that the queries themselves aren't as simple as they appear at first glance.

darrellwarde commented 1 year ago

At first glance, this sounds like a problem with Apollo Server (or your configuration of, or the environment that it is being run in) as opposed to a problem with this library itself. But as per above, if you can provide us with steps to reproduce (especially type definitions and the slow query), we can take a look.

Hashdhi commented 1 year ago

@mjfwebb and @darrellwarde I have attached both the graphql file and index .js (index.js.txt) [ zip file] after multiple time reload of sandbox generated SDL file attached in the zip .

database : Neo4j 4.3.5 OS : Windows 10 Other versions are mentioned above . cmd to start : node index.js Database size very very small 48 nodes and 96 relationships. When we hit http://localhost:4000/ in the browser, apollo sandbox is opened  .

Below is graphql query  query:

  devices(where: {id: "19000000081869290951670953448310"}) {
    activationStatus
    assocEquipmentConnection {
      edges {
        logicalPosition
        node {
          inventoryStatus
        }
      }
    }
  }

getting response after 5-10 minutes .

neo4j-graphql.zip Please let me know if you need more details.

Hashdhi commented 1 year ago

@mjfwebb @darrellwarde We need your help here . not sure why help wanted label is removed . Please let me know if you need more details

mjfwebb commented 1 year ago

@Hashdhi The help wanted label is used to signal to other contributors that we as the GraphQL team members would like assistance. Don't worry, we're looking at this :)

mjfwebb commented 1 year ago

We’ve been able to reproduce the very slow query experience you have described using your type definitions.

We'll discuss this, but there’s unfortunately nothing we can do immediately

Hashdhi commented 1 year ago

Glad that you had been able to replicate it . Please do update me once you find resolution . neo4j graphql is very critical for us .

MacondoExpress commented 1 year ago

Hi @Hashdhi! I believe this is not an issue with this library, but with Apollo Studio/Playground. The only performance issues that I have found are related to Apollo Studio, with the large schema and the default polling rate. Closing the Sandbox and using curl instead:

  curl --request POST \
    --header 'content-type: application/json' \
    --url http://localhost:4000/ \
    --data '{"query":"query Query {\n    devices {\n      activationStatus\n      assocEquipmentConnection {\n        edges {\n          logicalPosition\n          node {\n            inventoryStatus\n          }\n        }\n      }\n    }\n }"}'

works fine for me also with the large schema. Investigating a bit over the Apollo Studio issue, I noticed that the majority of the resources are used for the introspection requests before even reaching our resolvers, with Apollo Studio you can disable the polling mechanism as explained here: https://www.apollographql.com/docs/graphos/explorer/additional-features/#local-development

Let us know if your results are aligned with mine, if not, please share some test data that is enough for replication, I personally tried with several "devices" and related nodes without success!

Next week most of the team will be on holiday, so excuse us in advance for possible delays with the replies.

Merry Christmas!

mjfwebb commented 1 year ago

Hi @Hashdhi I also confirmed that there is no more query delay using Apollo Studio when the Auto Update option is turned off.

turn-off-polling

In case the gif doesn't work:

  1. Go to the Explorer tab
  2. Select the cog wheel button for settings
  3. Click Edit on Connection settings
  4. Toggle Auto Update so it is in the Off position

Hope that helps!