Skip to content

Feature/#16 attachment root query#141

Merged
jasonbahl merged 5 commits intowp-graphql:masterfrom
jasonbahl:feature/#16-attachment-root-query
May 24, 2017
Merged

Feature/#16 attachment root query#141
jasonbahl merged 5 commits intowp-graphql:masterfrom
jasonbahl:feature/#16-attachment-root-query

Conversation

@jasonbahl
Copy link
Copy Markdown
Collaborator

@jasonbahl jasonbahl commented May 24, 2017

This hardens the Attachment (mediaItem) Type definition and fixes a few bugs along the way.

Also includes tests for the MediaItem schema

You can now run queries like:

Get a list of mediaItems

{
  mediaItems {
    edges {
      node {
        id
        link
        caption
        altText
        description
        mediaType
        sourceUrl
        mediaDetails {
          width
          height
          file
          sizes {
            name
            file
            width
            height
            mimeType
            sourceUrl
          }
          meta {
            aperture
            credit
            camera
            caption
            createdTimestamp
            copyright
            focalLength
            iso
            shutterSpeed
            title
            orientation
            keywords
          }
        }
      }
    }
  }
}

mediaitemsquery

Or get the featured image for a specific post

{
  post(id: "cG9zdDoxMDEx") {
    id
    link
    postId
    featuredImage {
      id
      link
      caption
      altText
      description
      mediaType
      sourceUrl
      mediaDetails{
        width
        height
        file
        sizes{
          name
          file
          width
          height
          mimeType
          sourceUrl
        }
        meta{
          aperture
          credit
          camera
          caption
          createdTimestamp
          copyright
          focalLength
          iso
          shutterSpeed
          title
          orientation
          keywords
        }
      }
    }
  }
}

postfeaturedimagequery

- This adjusts the shape of the attachment (mediaItem) Type definition providing fields relevant to attachments/mediaItems, such as sizes, caption, altText, etc. . .
- Also adjusts the post object query test to remove the mimeType query as the field was moved to JUST the mediaItem type
…o feature/wp-graphql#16-attachment-root-query

# Conflicts:
#	src/Type/PostObject/PostObjectType.php
…s that support “thumbnail”

wp-graphql#16 - fixed some bugs with the mediaDetails not resolving properly on mediaItems
@jasonbahl jasonbahl mentioned this pull request May 24, 2017
@coveralls
Copy link
Copy Markdown

coveralls commented May 24, 2017

Coverage Status

Coverage increased (+0.09%) to 82.011% when pulling a4fdb28 on jasonbahl:feature/#16-attachment-root-query into 60c8a0e on wp-graphql:master.

1 similar comment
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.09%) to 82.011% when pulling a4fdb28 on jasonbahl:feature/#16-attachment-root-query into 60c8a0e on wp-graphql:master.

Copy link
Copy Markdown
Member

@CodeProKid CodeProKid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonbahl just a question on one small thing. Curious of your thoughts.

'type' => Types::string(),
'description' => esc_html__( 'Type of resource', 'wp-graphql' ),
'resolve' => function( \WP_Post $post, $args, $context, ResolveInfo $info ) {
return wp_attachment_is_image( $post->ID ) ? 'image' : 'file';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it would be more useful to return the mime type here, rather than just 'image' or 'file' here. We could just use get_post_mime_type() which pulls from the post_mime_type column. Thoughts?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to have some parity with the WP REST API:

https://github.com/WordPress/WordPress/blob/master/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L309

I did follow-up and added mimeType as a field as well though

@coveralls
Copy link
Copy Markdown

coveralls commented May 24, 2017

Coverage Status

Coverage increased (+0.03%) to 81.944% when pulling f3f3d10 on jasonbahl:feature/#16-attachment-root-query into 60c8a0e on wp-graphql:master.

@jasonbahl jasonbahl added the component: architecture Relating to fundamental architectural decisions label May 24, 2017
@jasonbahl jasonbahl added this to the Stable milestone May 24, 2017
@jasonbahl
Copy link
Copy Markdown
Collaborator Author

📸

@jasonbahl jasonbahl merged commit 6996b6d into wp-graphql:master May 24, 2017
@jasonbahl jasonbahl mentioned this pull request Jun 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: architecture Relating to fundamental architectural decisions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants