-
Notifications
You must be signed in to change notification settings - Fork 151
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
Renaming of @ignore directive #937
Comments
FWIW, when I implemented a similar feature for another library, I ended up going with # Computed fields tell the query parser to fetch certain fields
# from the database when querying for data.
directive @computed(
from: [String!] # field(s) to fetch from db instead of the api-layer field name
terminating: Boolean # don't query the db for any further down in the tree (useful when using dataloaders to fetch external data)
) on FIELD_DEFINITION As an example of the createdBy: User! @computed(from: ["createdById"], terminating: true) This tells our query parser to fetch Someone mentioned it in the other thread, but we also included (limited) support for deeper querysets by allowing dot notation in the Hope this is helpful! EDIT: One other thing I should mention: In our API, some of the fields with |
@oskarhane @darrellwarde @angrykoala I'm aware that this is a wholly different direction, but the previous attempt only allowed for querying primitive fields. I believe that with this generalization a custom resolver will now have access to the entire graph using the source node as a root. From #842 one could define a custom resolver with: type User {
id: ID!
firstName: String!
lastName: String!
fullName: String @ignore(dependsOn: ["firstName", "lastName"])
} The proposed way would be written as: type User {
id: ID!
firstName: String!
lastName: String!
fullName: String @ignore(dependsOn: "{ firstName lastName }")
} This will make it possible to have more complex requirements such as: type User {
id: ID!
firstName: String!
lastName: String!
friends: [User!]! @relationship(type: "HAS_FRIEND", direction: OUT)
friendsOfFriendsIds: [ID!]!
@ignore(
dependsOn: """
{
friends {
id
friends {
id
}
}
}
"""
)
} Here is a comparison: |
@nelsonpecora Thanks for the suggestions. I mentioned in the other thread that to me directive @custom(
from: String # selection set to determine what field(s) to fetch from db
) on FIELD_DEFINITION What utility do you think that selection sets offer? I don't want to overgeneralize the directive, but I think this direction may be better. I recently pushed a commit to the above branch dev...dmoree:feature/ignore-depends-on-selection-set that allows for variables in the custom resolver such that something like this is possible (using the above definition): interface FriendsProperties {
since: DateTime!
}
type User {
id: ID!
firstName: String!
lastName: String!
friends: [User!]! @relationship(type: "FRIENDS_WITH", direction: OUT, properties: "FriendsProperties")
newestFriendIds(since: DateTime!): [ID!]!
@custom(
from: """
{
friendsConnection(where: { edge: { since_GT: $since } }) {
totalCount
edges {
node {
id
}
}
}
}
"""
)
} I didn't make it explicit in the comment above, but this will take care of validation to make sure that the selection set is valid against the parent node. It also takes care of any argument mismatch by throwing an error about the need to alias. Although a good practice would be to simply circumvent that on the server by always aliasing the field in the selection set. I haven't yet found, however, a simple solution of validating the argument of the field against that of the selection set ( There is a PR graphql/graphql-js#3152 that seeks to implement fragment arguments which would solve this problem. The syntax would require the variable declarations on the interface FriendsProperties {
since: DateTime!
}
type User {
id: ID!
firstName: String!
lastName: String!
friends: [User!]! @relationship(type: "FRIENDS_WITH", direction: OUT, properties: "FriendsProperties")
newestFriendIds(since: DateTime!): [ID!]!
@custom(
from: """
fragment User_newestFriendIds on User {
friendsConnection(where: { edge: { since_GT: $since } }) {
totalCount
edges {
node {
id
}
}
}
}
"""
)
} Then, if that PR were to be implemented validation would be as simple as writing: fragment User_newestFriendIds($since: DateTime!) on User You also get fragment spreads making possible: extend type User {
newestFriendIds(since: DateTime!): [ID!]!
@custom(
from: """
fragment User_newestFriendIds on User {
friendsConnection(where: { edge: { since_GT: $since } }) {
totalCount
edges {
node {
...UserInfo
}
}
}
}
fragment UserInfo on User {
id
firstName
lastName
}
"""
)
} This would be more useful if there was one place where I don't want to over engineer this, but it appears quite flexible. |
Oh wow, this looks great! I agree about avoiding overengineering, and those flexible querysets seem like a great solution. I don't think my own use cases are complicated enough for fragments (they'd look like
|
Ignoring (no pun intended) the extended use cases above, we have made a start on this by renaming this directive as per the recommendation of @nelsonpecora in #979. Comments welcomed! |
We're going to close this issue. We're satisfied that the rename of |
As discussed in #842, the naming (and, potentially behaviour) of the
@ignore
directive is not intuitive enough. This issue exists to discuss the following:@ignore
name (e.g.@custom
,@computed
...)dependsOn
)The text was updated successfully, but these errors were encountered: