-
Notifications
You must be signed in to change notification settings - Fork 53
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
Pull entry drafts? #23
Comments
Not yet… but I can look at adding something for it in the next few days. How would you envision something like this working? Maybe, {
drafts(id:123) { # takes all the same parameters that `craft.entries` takes
title
...on News { # uses the same types as the `entries` query uses
body
}
}
} That's sort of a hack, and what I think I like a little more is adding it in to the Connections approach. The downside is all the added complexity for users just getting started with GraphQL. {
entriesConnection(id: 123) {
edges {
node {
# published field data
}
drafts { # an array of drafts for each edge
edges { # the draft edges
node { # each draft node
# draft field data
}
}
}
}
}
} |
Yea the connections approach seems way more powerful. The syntax seems a bit confusing to me but that’s just cause I’m pretty new to graphql in general, so I’m sure it will make more sense to me once I start using it. Thanks mark, really loving the plugin so far and excited to be able to really start using it on sites! |
This is implemented on {
drafts(id: 1) {
draftId
name
notes
...on PostDraft {
body
}
}
} This is my least favorite implementation, but it's the easiest to wrap your head around so I'm looking to clean up the code that drives this. A much more powerful approach is to use connections. Connections add a level of abstraction between your {
entries {
id
}
} There's no place there to provide any info about the total number returned, where you are in the loop, or how many pages. By converting {
entriesConnection {
edges { ... } # `entries` is now placed here
pageInfo { # we have room in the result set for pagination
currentPage
totalPages
}
}
} Taking the above one step further we can even abstract out the actual entry (edge) and provide additional detail on the entry. This is done through nodes, {
entriesConnection {
edges {
node { ... } # `entries` is now all the way down here
drafts { # for each `edge` (or entry) we now have all the draft data per entry!
…
}
}
}
} Let me know if this is helpful. I'll clean up the code and get this into the stable release soon-ish. |
This is implemented as described above. You can find this on release |
@markhuot Is there still a way to be able to pull a specific entry draft, or is it just all drafts at this point? |
How are you getting the draft id to pull? I think I can support pulling a specific draft, but I’m not sure how useful that is outside of the context of the entry… |
Re-opening this until we get this figured out. |
I'm looking to be able to use the preview button plugin and be able to pull a single draft in relation to an entry. For example |
Ah, I see. I'm curious though, where is the In any event, {
draft(draftId:123) {
entryId: id
...on EntryType {
draftData: customField
}
}
} |
Thanks for adding this back in! The |
Bringing drafts back in is now tagged in |
I understand that I can query the drafts for an article with the id = 5
But how could I only get the newest draft? Sorry I am pretty new to graphql |
@Jones-S , no need to apologize at all. I think:
However, what you'd do in a resolver, you can do outside, and I consider that the way. You lose on any efficiency the database might have given with its hyper-optimized manipulations and searches, but for data sizes generally with Craft, and in the case of drafts specifically, shouldn't be an issue. So, you can pull your list of drafts via CraftQL, and then select the one you want via PHP or JS. I'd use a map (php array_map) I think, and just look for a date or draftNo as you go through the results array, holding the record with max for the return. Something like that, anyway, rather than bother with a sort, since you don't need the code or cpu exercise to get results actually in order. A last or perhaps first point would be to look into why you want to do this. You may have a goal that needs it, but if it's just to find the draft Craft would be working on in a preview, you can get that directly, as @brandonkelly explains here: #31 (comment) |
Thank you for your explanation. It was indeed about previews and in the meantime I got to work both of them. For the moment not with apollo, but just with an axios call where I forward the token. 👍 |
Is it possible to pull entry drafts via CraftQL?
The text was updated successfully, but these errors were encountered: