Skip to content

Fastify Example #10

Open
Open
@mthota15

Description

Any example on how to run it with fastify? I was able to get postgraphile run with fastify. Now i am trying to include this plugin for file upload but not able to make it work.

Fastify with postgrapgile

const Fastify = require('fastify');
const helmet = require('fastify-helmet');
const cors = require('fastify-cors');
const Compress = require('fastify-compress');
const { postgraphile } = require('postgraphile');
const PgSimplifyInflectorPlugin = require('@graphile-contrib/pg-simplify-inflector');
const PostGraphileNestedMutations = require('postgraphile-plugin-nested-mutations');

const app = Fastify({
  logger: true,
});

// Register Plugins
app.register(cors);
app.register(helmet);
app.register(Compress, {
  global: true,
  threshold: 256, // bytes; below this size will not be compressed
});

// app.use(expressCompression({threshold: 0})); // working

// app.register(fastifyCompression, {threshold: 0}); // not working

app.use(
  postgraphile(
    'postgres://postgres:postgres@localhost:5432/demo_1?sslmode=disable',
    'app_public',
    {
      dynamicJson: true,
      appendPlugins: [PgSimplifyInflectorPlugin, PostGraphileNestedMutations],
      enhanceGraphiql: process.env.NODE_ENV !== 'production' ? true : false,
      graphileBuildOptions: {
        nestedMutationsSimpleFieldNames: true,
        nestedMutationsDeleteOthers: false,
      },
      disableQueryLog: process.env.NODE_ENV !== 'production' ? true : false,
      graphiql: process.env.NODE_ENV !== 'production' ? true : false,
      watchPg: process.env.NODE_ENV !== 'production',
    }
  )
);

app.listen(process.env.PORT || 3000, (err) => {
  if (err) {
    app.log.error(err);
    process.exit(1);
  }
});

i tried combing with this plugin: https://www.npmjs.com/package/fastify-gql-upload but no luck

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions