SOFA icon indicating copy to clipboard operation
SOFA copied to clipboard

Only expose certian Queries/Mutations

Open Borduhh opened this issue 2 years ago • 6 comments

We are contemplating using SOFA to generate an external REST API from our federated GraphQL API, but we want to be able to choose which queries/mutations we expose via the REST API. Is that possible with SOFA?

Borduhh avatar May 25 '22 15:05 Borduhh

Ditto

currentoor avatar Nov 11 '22 22:11 currentoor

That seems crucial for any serious production use yes.

Is there a way today to achieve something similar maybe by transforming the schema before feeding it to SOFA?

We're currently doing this with graphql-tools as such:

import { FilterRootFields, PruneSchema, schemaFromExecutor, wrapSchema } from "@graphql-tools/wrap"

const operationWhitelist = [
  "someoperation",
]

const schema = wrapSchema({
  schema: await schemaFromExecutor(executor),
  executor,
  transforms: [new FilterRootFields((_operationName, fieldName) => operationWhitelist.includes(fieldName)), new PruneSchema()],
})

simoneromano96 avatar Jun 26 '23 15:06 simoneromano96

To those who try to do this with Apollo federation, I managed to get this to work.

import { FilterRootFields, PruneSchema, wrapSchema } from '@graphql-tools/wrap';  

  const operationWhitelist = ['createUser', 'updateUser', 'user', 'users'];
  const wrappedSchema = wrapSchema({
    schema: schema,
    transforms: [
      new FilterRootFields((_operationName, fieldName) => {
        return operationWhitelist.includes(fieldName);
      }),
      new PruneSchema(),
    ],
  });

Then you pass the wrapped schema to Apollo server as usual

yuraxdrumz avatar Jul 04 '23 09:07 yuraxdrumz

We also evaluated using Sofa for a public facing API, but this issue and #776 are pretty essential for that. Is this planned for the near future @ardatan or @Urigo ?

itpropro avatar Apr 11 '24 08:04 itpropro

Thanks everyone for commenting here We are aiming to tackle this soon Is anyone in this thread willing to go on a call with us, walk us through your current setup and your needs, get a shared Slack channel going with The Guild and test the new versions with us till we get it right? If yes, simply email me (my email is on my GitHub profile)

Urigo avatar Apr 17 '24 11:04 Urigo