Comments (11)
Closing this now as we've determined that user-supplied custom directives is a non-goal for graphql-js at this time.
from graphql-js.
@leebyron Hmm. This doesn't sit well with me. Directives are a great way for graphql server administrators to provide custom functionality to their graphql users.
From the spec:
GraphQL servers define what directives they support. For each usage of a directive, the directive must be available on that server.
This seems to be that so long as a directive can be found on the server the users of graphql should be fully capable of using said directive. Hence, there ought to be a way for graphql server administrators to add/register directives.
From my review of the source it appears that when instantiating a GraphQLSchema
you can specify custom directives as part of the GraphQLSchemaConfig#directives
config property, but there is no way to actually execute said directives (at least from what I can tell).
For those looking for similar functionality and not an outdated repo, try giving https://github.com/smooth-code/graphql-directive a look. Just don't expect this to work forever.
from graphql-js.
Can you explain more concretely what custom directives you wish to provide and how you would imagine implementing them?
I'm curious because we're actually considering a change that removes directives from the schema completely.
from graphql-js.
TLDR
Use this package to add custom directive support: https://github.com/smooth-code/graphql-directive
from graphql-js.
Can you explain more concretely what custom directives you wish to provide and how you would imagine implementing them? @leebyron
Well, I use graphql-faker to define a schema with fake data. Frontend developers feel really great with it, cause it consists of easy-to-run-graphql-server and there is no need in heavy backend, databases, etc.
$ graphql-faker --open ./schema.graphql
To fake data, schema must contain some additional directives: @fake(…)
and @examples(…)
. They describe the true nature of entities: names, emails, phone numbers, …
type Query {
hello: String! @fake(type: firstName)
}
As a GraphQL API developer, I write the following code:
import { graphql, buildSchema } from 'graphql'
const schema = buildSchema(fs.readFileSync('./schema.graphql', 'utf8'))
app.use('/graphql', graphqlHTTP({ schema, rootValue }))
And I want the graphql parser just to ignore those @fake
and @examples
directives, and have a single schema.graphql
file both for graphql-faker, and for my graphql API.
As a bypass I wrote a regex, though it's not a reliable way (context-grammar, braces, all that stuff), resolving custom directives after grammar parsing is better.
from graphql-js.
It seemed like a gap in the implementation, and I'm interested in contributing. I don't have any concrete examples at this time.
from graphql-js.
Oh ok, I understand.
To be clear, directives are not designed to be extended by users of graphql, but by future versions of graphql core itself.
That's the reason we're considering removing them from schema. It's too confusing as schema is something a user of graphql defines and produces, and directives being accessible from the same portion of code is the thing that doesn't look like the others.
from graphql-js.
I think the grammar is confusing for people reading graphql for the first time, if you replace the @
with a .
they are practically chained calls which is well known pattern
from graphql-js.
I'm not sure I agree chained calls is a well known pattern unless you've used Facebook's pre-spec graphql. Chained calls were replaced by field arguments. Directives is an entirely new concept
from graphql-js.
Check this extention for custom directive:
https://github.com/lirown/graphql-custom-directive
from graphql-js.
@xamgore Yes, it's a valid issue but it's not related to this issue.
Can you please open a new issue?
from graphql-js.
Related Issues (20)
- IHeyReally.org
- Suggestion: Bundling in v17, ESM, CJS, and the dual package hazard HOT 9
- Just to give my 2c, I'm not sure if `exports.development` and `exports.production` target conditionsa are widely supported, so some `import.env` shenanigans may still be necessary until that's widely adopted. HOT 1
- Collection of libraries and how they import from `graphql` HOT 20
- `process.env`, `globalThis`, and `typeof process` HOT 21
- Introspection queries don't support `@oneOf` HOT 2
- Tutorial data HOT 2
- astFromValue fails with a custom scalar serializing to an object value HOT 5
- In a response to a query about an Issue, the URL and other info is missing for links created with Reference editor button HOT 5
- author/committer -> user fields returning NULL for commits committed by user
- [email protected]
- npm link with graphql package breaks application HOT 2
- IHeyReally.com HOT 1
- Can I ask what is the progress here? Is there a solution being worked on? Do we have some timeline? Or progress with issue? Thanks!
- IHeyReally.com
- Typescript error with 16.9.0 (re ThunkObjMap) HOT 3
- Notice: default branch is now `16.x.x` HOT 2
- <a href="https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/12261526/38307428/4135/#/?version=2"><img src="https://s3.amazonaws.com/cla-project-logo-prod/cla-not-signed.svg" alt="CLA Not Signed" align="left" height="28" width="328"></a><br/><br /><ul><li><a href='https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/12261526/38307428/4135/#/?version=2' target='_blank'>:x:</a> - login: @Heyitsquoracom / name: [email protected] . The commit (b6081f914f0c5c22ee48d26aff4b473bf17627ce) is not authorized under a signed CLA. <a href='https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/12261526/38307428/4135/#/?version=2' target='_blank'>Please click here to be authorized</a>. For further assistance with EasyCLA, <a href='https://jira.linuxfoundation.org/servicedesk/customer/portal/4' target='_blank'>please submit a support request ticket</a>.</li></ul><!-- Date Modified: 2024-06-28 04:40:51.630768 -->
- Error with version v16.9.0: `Can't resolve '@apollo/subgraph/dist/directives''` HOT 1
- Type is incorrect in graphql ExecutionResult with new type GraphQLFormattedError 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-js.