-
Notifications
You must be signed in to change notification settings - Fork 109
🎉 NEW RULE: Compare operation/fragment name to the file name #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 04dfab3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest changes of this PR are available as alpha in npm (based on the declared |
|
@dotansimha thanks a lot, as always incredible feedback/support from The Guild! 🙏👍🔥 So let's start forming requirements. What we have nowIn our client apps, we have the following 1) UsersPaginationQuery.graphql query UsersPaginationQuery {
userPagination {
count
items {
...UserDataFragment
}
}
}2) UserUpdateMutation.graphql mutation UserUpdateMutation($input: UserCreateInput!) {
user {
update(input: $input) {
recorded
record {
...UserDataFragment
}
}
}
}3) UserUpdateSubscription.graphql subscription UserUpdateSubscription($id: ID!) {
userUpdate(id: $id) {
...UserDataFragment
}
}
}4) UserDataFragment.graphql fragment UserDataFragment on User {
id
nickname
avatar
}We are using exact naming for operations/fragments and files. It helps understand what exactly inside. Also according to this requirement, we have suffixes Query/Mutation/Subscription/Fragment to distinguish what exactly inside. And when we are working with React components and Typescript we understood what type/interface we are using – from graphql or some internal client type. Our current problems:
Desirable options
Desirable options (v2) most configurable formatBy the way, it will be nice if we can somehow provide the ability to set different patterns for different operations. In such case config can have the following form: {
query: '%{CamelCase}Query.graphql',
mutation: '%{CamelCase}Mutation.graphql',
subscription: '%{CamelCase}Subscription.graphql',
fragment: '%{camelCase}.graphql', // by default should be '%{CamelCase}Fragment.graphql',
}Instead of masks %{}, we can use more powerful regexps which provide the ability to use OR, Neglect and any crazy pattern logic: {
query: '[A-Z]{1}[a-zA-Z0-9_]*Query\.(graphql|gql)', // by default should be '[A-Z]{1}[a-zA-Z0-9_]*Query\.graphql',
mutation: '[A-Z]{1}[a-zA-Z0-9_]*Mutation\.graphql',
subscription: '[A-Z]{1}[a-zA-Z0-9_]*Subscription\.graphql',
fragment: '[A-Z]{1}[a-zA-Z0-9_]*\.graphql', // by default should be '[A-Z]{1}[a-zA-Z0-9_]*Fragment\.graphql',
}Such config a little bit verbose, but helps precisely control filenames. |
Another pluginPS. This rule should control only filenames. But what about the similar new rule which will control operation names? Eg with the following config: {
query: '[A-Z]{1}[a-zA-Z0-9_]*Query',
mutation: '[A-Z]{1}[a-zA-Z0-9_]*Mutation',
subscription: '[A-Z]{1}[a-zA-Z0-9_]*Subscription',
fragment: '[A-Z]{1}[a-zA-Z0-9_]_[a-zA-Z0-9_]+', // Relay pattern `TypeName_prop` by default should be '[A-Z]{1}[a-zA-Z0-9_]*Fragment',
noDoubleSuffixes: true, // avoid QueryQuery, MutationQuery
} |
ccf4190 to
b7a25f8
Compare
b87fa14 to
04dfab3
Compare
|
@B2o5T made this a reality :) It's going to be part of the next release! |
|
Available in |
Inspiration: https://twitter.com/nodkz/status/1397418250057797632
I think we have many options here, so I'm not sure how to address the comparison:
userByIdcan match a file nameuser-by-id.graphql)Usercan be in a file calleduser.fragment.graphql)