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

enhancement/optimize graphql server for production builds #1277

Conversation

thescientist13
Copy link
Member

@thescientist13 thescientist13 commented Sep 5, 2024

Related Issue

N / A

Noticed that tests were intermittently failing due to an extra -cache.json file being generated. (i think maybe it was always there?)

1) Build Greenwood With: 
      Children from GraphQL
        Home Page output w/ ChildrenQuery
          should output a single (partial) *-cache.json file, one per each query made:

    AssertionError: expected [ Array(2) ] to have a length of 1 but got 2
    + expected - actual

    -2
    +1
    
    at Context.<anonymous> (file:///Users/owenbuckley/Desktop/greenwood/packages/plugin-graphql/test/cases/query-children/query-children.spec.js:171:97)

Not really causing any harm, but extra work nonetheless, and threw off our tests. Seems like an IntrospectionQuery is being run and causing the extra cache file to be generated, perhaps something only manifesting now since this introspection seems to happen on a polling interval?

➜  greenwood git:(enhancement/optimize-graphql-server-for-production) ✗ ls -l public/
total 272
-rw-r--r--  1 owenbuckley  staff    454 Sep  4 20:54 1689629932-cache.json
-rw-r--r--  1 owenbuckley  staff  29099 Sep  4 20:54 231435726-cache.json
-rw-r--r--  1 owenbuckley  staff   1008 Sep  4 20:54 404.html
-rw-r--r--  1 owenbuckley  staff    234 Sep  4 20:54 758806547.4ef0df00.js.map
drwxr-xr-x  4 owenbuckley  staff    128 Sep  4 20:54 blog
-rw-r--r--  1 owenbuckley  staff   2579 Sep  4 20:54 graph.json
-rw-r--r--  1 owenbuckley  staff   1878 Sep  4 20:54 index.html
-rw-r--r--  1 owenbuckley  staff     38 Sep  4 20:54 manifest.json
-rw-r--r--  1 owenbuckley  staff  16168 Sep  4 20:54 posts-list.1f790240.js
-rw-r--r--  1 owenbuckley  staff  43135 Sep  4 20:54 posts-list.1f790240.js.map
-rw-r--r--  1 owenbuckley  staff  19717 Sep  4 20:54 resources.json
    write cache {
      query: 'query IntrospectionQuery {\n' +
        '  __schema {\n' +
        '    queryType {\n' +
        '      name\n' +
        '    }\n' +
        '    mutationType {\n' +
        '      name\n' +
        '    }\n' +
        '    subscriptionType {\n' +
        '      name\n' +
        '    }\n' +
        '    types {\n' +
        '      ...FullType\n' +
        '    }\n' +
        '    directives {\n' +
        '      name\n' +
        '      description\n' +
        '      locations\n' +
        '      args {\n' +
        '        ...InputValue\n' +
        '      }\n' +
        '    }\n' +
        '  }\n' +
        '}\n' +
        '\n' +
        'fragment FullType on __Type {\n' +
        '  kind\n' +
        '  name\n' +
        '  description\n' +
        '  fields(includeDeprecated: true) {\n' +
        '    name\n' +
        '    description\n' +
        '    args {\n' +
        '      ...InputValue\n' +
        '    }\n' +
        '    type {\n' +
        '      ...TypeRef\n' +
        '    }\n' +
        '    isDeprecated\n' +
        '    deprecationReason\n' +
        '  }\n' +
        '  inputFields {\n' +
        '    ...InputValue\n' +
        '  }\n' +
        '  interfaces {\n' +
        '    ...TypeRef\n' +
        '  }\n' +
        '  enumValues(includeDeprecated: true) {\n' +
        '    name\n' +
        '    description\n' +
        '    isDeprecated\n' +
        '    deprecationReason\n' +
        '  }\n' +
        '  possibleTypes {\n' +
        '    ...TypeRef\n' +
        '  }\n' +
        '}\n' +
        '\n' +
        'fragment InputValue on __InputValue {\n' +
        '  name\n' +
        '  description\n' +
        '  type {\n' +
        '    ...TypeRef\n' +
        '  }\n' +
        '  defaultValue\n' +
        '}\n' +
        '\n' +
        'fragment TypeRef on __Type {\n' +
        '  kind\n' +
        '  name\n' +
        '  ofType {\n' +
        '    kind\n' +
        '    name\n' +
        '    ofType {\n' +
        '      kind\n' +
        '      name\n' +
        '      ofType {\n' +
        '        kind\n' +
        '        name\n' +
        '        ofType {\n' +
        '          kind\n' +
        '          name\n' +
        '          ofType {\n' +
        '            kind\n' +
        '            name\n' +
        '            ofType {\n' +
        '              kind\n' +
        '              name\n' +
        '              ofType {\n' +
        '                kind\n' +
        '                name\n' +
        '              }\n' +
        '            }\n' +
        '          }\n' +
        '        }\n' +
        '      }\n' +
        '    }\n' +
        '  }\n' +
        '}\n',
      variables: {}
    }
  

Summary of Changes

  1. Ignore introspection queries from caching
  2. Disable the playground for production builds

Ultimately I had to resort to just blocking the IntrospectionQuery operation since even turning introspection off and disabling the playground would cause weird Apollo server errors or would make the call anyway. 🤷‍♂️

@thescientist13 thescientist13 added enhancement Improve something existing (e.g. no docs, new APIs, etc) Plugins Greenwood Plugins Content as Data alpha.6 v0.30.0 labels Sep 5, 2024
@thescientist13 thescientist13 added this to the 1.0 milestone Sep 5, 2024
@thescientist13 thescientist13 force-pushed the enhancement/optimize-graphql-server-for-production branch from 9d01ba6 to 998e813 Compare September 20, 2024 21:24
@thescientist13 thescientist13 merged commit e749a14 into release/0.30.0 Sep 20, 2024
8 checks passed
@thescientist13 thescientist13 deleted the enhancement/optimize-graphql-server-for-production branch September 20, 2024 21:45
@thescientist13 thescientist13 mentioned this pull request Oct 18, 2024
39 tasks
thescientist13 added a commit that referenced this pull request Nov 2, 2024
* optimize graphql server for production builds

* fix linting

* tweak coverage thresholds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.7 Content as Data enhancement Improve something existing (e.g. no docs, new APIs, etc) Plugins Greenwood Plugins v0.30.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

1 participant