Comments (12)
Yes, thank you! For anyone else having the same problem, it should look like this:
const { fragmentReplacements, schema } = applyMiddleware(
plainSchema,
permissions,
)
// create transforms array for transformSchema
const transforms = [new ReplaceFieldWithFragment(schema, fragmentReplacements)]
// apply transformations
const finalSchema = transformSchema(schema, transforms)
from graphql-shield.
Hey @nemcek π
That's an interesting question, and indeed you are right! The current version doesn't support fragments
. Fragments are a way of telling graphql resolver which information your resolver requires to work correctly.
The next version of shield should introduce this with the following syntax. Right now, we fully depend on graphql-tools
PR and grpahql-middleware
fragments support which should land in no time.
const nestedRule = rule({
cache: 'strict',
fragment: 'fragment UserID on User { id }',
})(async ({ id }, args, ctx, info) => {
return somethingWithID(id)
})
I hope this covers your idea. Tell me if you have any thoughts on this as well! π
from graphql-shield.
Hey @kratam π
Could you also provide schema
and rules
? Also, you should note thay you have to use fragmentReplacements
returned by middleware
; maybe we should indicate that in the docs.
from graphql-shield.
What libraries are transformSchema
and ReplaceFieldWithFragment
from?
from graphql-shield.
I believe transformSchema
from graphql-tools
is now called wrapSchema
from graphql-shield.
Oh, sweet!
Just to be sure I understood it correctly. In the next version if I use rule with a fragment, for example as:
const isOwner = rule({
fragment: 'fragment UserID on User { id }',
})(async (parent, args, ctx, info) => {
return ctx.user.items.some(id => id === parent.id)
})
then I can be sure that parent.id
will be populated, right?
If that's the case then shield solves all my use-cases. Love it!
from graphql-shield.
Yeah, thatβs exactly that! Perfect ππ
from graphql-shield.
Is it live? parent
is always undefined
even when I set cache: 'strict'
(the fragment
part doesn't even matter):
const isOwner = rule({
cache: 'strict',
fragment: 'fragment Id on Item { id }',
})(async (parent, args, ctx: Context, info) => {
console.log(parent) // undefined
return true
})
Note: I'm using:
"apollo-server-express": "^2.0.5",
"graphql-middleware": "^1.7.1",
"graphql-shield": "^3.2.0",
from graphql-shield.
Wow, super fast response! :) How can I pass fragmentReplacements
to ApolloServer
?
from graphql-shield.
Hey π
Sorry for the delayed response. fragmentReplacements
are part of schema forwarding; graphql-binding
supports this using fragmentReplacements
parameter.
Besides that, you could also use standalone transforms
which are supported by ApolloServer, especially ReplaceFieldWithFragment
https://www.apollographql.com/docs/graphql-tools/schema-transforms.html#Other
I hope this helps you with your problem π
from graphql-shield.
It looks like ReplaceFieldWithFragment
should be accessible from @graphql-tools/delegate
according to this thread, but I'm getting the following error:
Module '"@graphql-tools/delegate"' has no exported member 'ReplaceFieldWithFragment'
from graphql-shield.
Has anyone been able to configure fragmentReplacements
for NestJS and Apollo Server? It looks like ReplaceFieldWithFragment
is deprecated now.
from graphql-shield.
Related Issues (20)
- Execute root fields rules prior graphql execute phase
- Add the ability to use Fragments and post-execution rules with the single server/schema
- Add Typescript typings to rule args
- Add the ability to attach rules using GraphQL Directives
- CI: add codecov reports
- Provide a way to expose authorization metadata through the graphql schema
- GraphQL Shield Roadmap
- 7.6.4 ESM build broken HOT 5
- Documentation website down HOT 1
- How to use `if` condition in GraphQL Shield HOT 2
- Shield rules type generation based on schema HOT 1
- Feature request: wildcard functionality for field names
- Update [email protected] module to avoid @types/lodash and babel runtime in production deps
- fallbackError loses custom error types
- fallbackRule context information HOT 2
- Question: Is there a way to return objects on rules?
- ..
- Typo in the Docs
- Shield permissions only working properly with 'debug: true' HOT 1
- Performance -- every field wrapped is unnecessarily wrapped in a promise HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-shield.