Skip to content

Instantly share code, notes, and snippets.

@thumphries
Last active December 1, 2020 03:10

Revisions

  1. thumphries revised this gist Dec 1, 2020. 1 changed file with 40 additions and 1 deletion.
    41 changes: 40 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,19 @@

    Repro attempt for https://github.com/apollographql/federation/issues/211

    Usage:
    ## Summary

    ```
    @apollo/gateway -> @apollo-server-lambda -> serverless-webpack
    ```

    Expecting a single .js bundle that works when required from Node 12.x.

    Getting a single .js bundle that contains some busted webpacky bits:
    - requiring util (?)
    - reading local .wasm files at runtime

    ## Usage

    ```sh
    npm install
    @@ -18,3 +30,30 @@ Should spit out a module resolution error, like:
    Thrown:
    Error: Cannot find module 'util'
    ```

    ## Getting past the require('util') error

    If you poke `node_modules/@apollo/query-planner-wasm/`, changing line 4:

    ```
    const { TextDecoder } = require(String.raw`util`);
    ```

    ... replacing with:

    ```
    const { TextDecoder } = require('util');
    ```

    ... and rebuild, unzip, run again, you get the desired error:

    ```
    ```

    ## Guessing about wasm-pack

    It seems like this package is bundled with `wasm-pack -t nodejs`.

    This use case might expect `-t bundler` and some kind of `.wasm$`
    webpack loader?
  2. thumphries revised this gist Dec 1, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    build/
    node_modules/
  3. thumphries revised this gist Dec 1, 2020. 6 changed files with 8714 additions and 1 deletion.
    21 changes: 20 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,20 @@
    #
    # `@apollographql/federation#211`

    Repro attempt for https://github.com/apollographql/federation/issues/211

    Usage:

    ```sh
    npm install
    npm run package
    cd build
    unzip lambda.zip
    node -e "require('.').main()"
    ```

    Should spit out a module resolution error, like:

    ```
    Thrown:
    Error: Cannot find module 'util'
    ```
    18 changes: 18 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    import { ApolloGateway } from '@apollo/gateway';
    import { ApolloServer } from 'apollo-server-lambda';

    const gateway = new ApolloGateway({
    serviceList: [{name: 'accounts', url: 'https://accounts.fake.com'}],
    });

    const server = new ApolloServer({
    gateway,
    subscriptions: false,
    });

    const handler = server.createHandler();

    export const main = async (event, context) => {
    return handler(event, context);
    };

    8,620 changes: 8,620 additions & 0 deletions package-lock.json
    8,620 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
    21 changes: 21 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    {
    "name": "gateway",
    "version": "0.0.0",
    "engines": {
    "node": ">=12.0.0"
    },
    "devDependencies": {
    "serverless": "^2.13.0",
    "serverless-webpack": "^5.3.5",
    "webpack": "^5.6.0",
    "webpack-cli": "^4.2.0"
    },
    "dependencies": {
    "@apollo/gateway": "^0.21.3",
    "apollo-server": "^2.19.0",
    "apollo-server-lambda": "^2.19.0"
    },
    "scripts": {
    "package": "serverless package -v --package ./build"
    }
    }
    19 changes: 19 additions & 0 deletions serverless.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    service: lambda

    provider:
    name: aws
    region: us-west-2
    runtime: nodejs12.x
    environment:
    LAMBDA_TASK_ROOT: true

    custom:
    webpack:
    webpackConfig: webpack.config.js

    plugins:
    - serverless-webpack

    functions:
    main:
    handler: index.main
    16 changes: 16 additions & 0 deletions webpack.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    const path = require ('path');

    const slsw = require ('serverless-webpack');


    module.exports = {
    mode: 'production',
    entry: slsw.lib.entries,
    target: 'node',
    node: {
    __dirname: false,
    },
    experiments: {
    asyncWebAssembly: true,
    },
    };
  4. thumphries created this gist Dec 1, 2020.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    #