How to use sofa-api - 4 common examples

To help you get started, we’ve selected a few sofa-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spacexland / api / src / servers / rest.ts View on Github external
export default (app, { schema, context }) => {
  const openApi = OpenAPI({
    schema,
    info: {
      title: "SpaceX REST API"
    }
  });

  const basePath = "/rest";

  app.use(cors());

  app.use(
    basePath,
    sofa({
      schema,
      context,
      onRoute(info) {
        openApi.addRoute(info, { basePath });
      }
    })
  );

  // writes every recorder route
  openApi.save("./swagger.json");

  // expose rest docs
  app.use(basePath, swaggerUi.serve, swaggerUi.setup(swaggerDocument));
};
github aerogear / graphback / templates / apollo-rest-starter / src / index.ts View on Github external
async function start() {
  const app = express()

  app.use(cors())

  app.get("/health", (req, res) => res.sendStatus(200))

  const schema = makeExecutableSchema({
    typeDefs,
    resolvers,
    resolverValidationOptions: {
      requireResolversForResolveType: false
    }
  });

  app.use("/rest", useSofa({
    schema,
  }))

  // connect to db
  const client = await connect(config.db);

  const apolloConfig = {
    schema,
    context: async ({
      req
    }: { req: express.Request }) => {
      // pass request + db ref into context for each resolver
      return {
        req: req,
        db: client,
        pubsub
github birkir / prime / packages / prime-core / src / server.ts View on Github external
pubSub.subscribe('REBUILD_EXTERNAL', async payload => {
    if (external) {
      log('schemas have changed', payload.name);
    }

    external = await createExternal(connection);
    externalServer.schema = external.schema;
    externalServer.context = external.context;
    externalServer.schemaDerivedData = externalServer.generateSchemaDerivedData(
      externalServer.schema
    );

    if (config.sofaApi) {
      app.use(
        `${config.path}api`,
        sofa({
          schema: external.schema,
          ignore: ['Prime_Document'],
        })
      );
    }
  });
github spacexland / api / src / servers / rest.ts View on Github external
export default (app, { schema, context }) => {
  const openApi = OpenAPI({
    schema,
    info: {
      title: "SpaceX REST API"
    }
  });

  const basePath = "/rest";

  app.use(cors());

  app.use(
    basePath,
    sofa({
      schema,
      context,
      onRoute(info) {

sofa-api

Create REST APIs with GraphQL

MIT
Latest version published 6 days ago

Package Health Score

84 / 100
Full package analysis

Popular sofa-api functions