Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds native GraphQL support for fields that didn't already resolve neatly as strings: Address, Notes and PredefinedDate. It may satisfy #93 depending on how elaborately you'd like to support GraphQL.
Changed Behavior
Previously, querying a Notes or Predefined Date field would return
null
in each case. This instead returns the rendered note and date respectively. The date is formatted according toFormatDateTime::DEFAULT_FORMAT
viacraft\gql\types\DateTime
since that's how Craft returns its ownDateTime
values via GraphQL.The Address field was previously returning the complete address as formatted markup. This registers a new GraphQL object entity so that Sprout Fields can make each Address nugget available individually.
Current Behavior (without PR)
Query (each
sprout*
handle being a custom field type):Response:
Updated Behavior (with PR)
Query:
Response:
How it Works
Each modified field type needed to clarify how it should be reduced to scalar types for GraphQL. Craft automatically tries—and mostly succeeds with the rest of the field types—to get and use the string value of a given field. Each adjustment here implements
getContentGqlType()
on the respective field class.Predefined Date is the simplest, returning Craft's
GqlDateTimeType::getType()
.Notes is more atypical for a field type. It returns a string type and uses a
resolve
parameter that provides thenotes
property as that string.Address returns an object with properties that map to strings. To do this, it creates and registers a new object type, each property mapping directly to those that already exist on the field's address pieces. Note that this type is re-used by
GqlEntityRegistry::getEntity()
if it already exists, for healthy performance.Limitations
Reasons you may not want to merge immediately:
If you have any questions, objections or requests let me know!