Skip to content
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

Add Graphql console controller #4834

Merged

Conversation

khalwat
Copy link
Contributor

@khalwat khalwat commented Aug 28, 2019

Adds two console commands:

  • graphql/dump-schema Dump out a given GraphQL schema to a file
  • graphql/print-schema Print out a given GraphQL schema

Both operate on either the currently active schema, or fall back on the public schema. You can also pass a token parameter in to designate a schema by token:

--token: string
  The token to look up to determine the appropriate GraphQL schema

e.g.:

graphql/dump-schema --token=woof

This is especially useful for IDE auto-completion of GraphQL schemas.

Signed-off-by: Andrew Welch <andrew@nystudio107.com>
@khalwat
Copy link
Contributor Author

khalwat commented Aug 28, 2019

Example output:

"""
This directive allows for formatting any date to the desired format. It can be
applied to all fields, but changes anything only when applied to a DateTime
"""
directive @formatDateTime(
  """This specifies the format to use. It defaults to the [Atom date time"""
  format: String = "Y-m-d\\\\TH:i:sP"

  """
  The full name of the timezone, defaults to UTC. (E.g., America/New_York)
  """
  timezone: String = "UTC"
) on FIELD

"""
This directive is used to return a URL for an [asset
tranform](https://docs.craftcms.com/v3/image-transforms.html). It accepts the
same arguments you would use for a transform in Craft and adds the `immediately`
"""
directive @transform(
  """The handle of the named transform to use."""
  handle: String

  """Width for the generated transform"""
  width: Int

  """Height for the generated transform"""
  height: Int

  """The mode to use for the generated transform."""
  mode: String

  """The position to use when cropping, if no focal point specified."""
  position: String

  """The interlace mode to use for the transform"""
  interlace: String

  """The quality of the transform"""
  quality: Int

  """The format to use for the transform"""
  format: String

  """
  Whether the transform should be generated immediately or only when the image is requested us
ed the generated URL
  """
  immediately: Boolean
) on FIELD

"""This is the interface implemented by all assets."""
interface AssetInterface {
  """The id of the entity"""
  id: ID

  """The uid of the entity"""
  uid: String

  """The element’s title."""
  title: String

  """The element’s slug."""
  slug: String

  """The element’s URI."""
  uri: String

  """Whether the element is enabled or not."""
  enabled: Boolean

  """Whether the element is archived or not."""
  archived: Boolean

  """The ID of the site the element is associated with."""
  siteId: Int

  """
  The element’s search score, if the `search` parameter was used when querying for the element
.
  """
  searchScore: String

  """Whether the element has been soft-deleted or not."""
  trashed: Boolean

  """The element's status."""
  status: String

  """The date the element was created."""
  dateCreated: DateTime

  """The date the element was last updated."""
  dateUpdated: DateTime

  """The ID of the volume that the asset belongs to."""
  volumeId: Int

  """The ID of the folder that the asset belongs to."""
  folderId: Int

  """The filename of the asset file."""
  filename: String

  """The file extension for the asset file."""
  extension: String

  """Whether a user-defined focal point is set on the asset."""
  hasFocalPoint: Boolean

  """
  The focal point represented as an array with `x` and `y` keys, or null if it's not an image.
  """
  focalPoint: [Float]

  """The file kind."""
  kind: String

  """The file size in bytes."""
  size: String

  """The height in pixels or null if it's not an image."""
  height: Int

  """The width in pixels or null if it's not an image."""
  width: Int

  """An `<img>` tag based on this asset."""
  img: String

  """The full URL of the asset."""
  url: String

  """The file’s MIME type, if it can be determined."""
  mimeType: String

  """The asset's path in the volume."""
  path: String

  """The date the asset file was last modified."""
  dateModified: DateTime
}

"""The `DateTime` scalar type represents a point in time."""
scalar DateTime

type Element implements ElementInterface {
  """The id of the entity"""
  id: ID

  """The uid of the entity"""
  uid: String

  """The element’s title."""
  title: String

  """The element’s slug."""
  slug: String

  """The element’s URI."""
  uri: String

  """Whether the element is enabled or not."""
  enabled: Boolean

  """Whether the element is archived or not."""
  archived: Boolean

  """The ID of the site the element is associated with."""
  siteId: Int

  """
  The element’s search score, if the `search` parameter was used when querying for the element
.
  """
  searchScore: String

  """Whether the element has been soft-deleted or not."""
  trashed: Boolean

  """The element's status."""
  status: String

  """The date the element was created."""
  dateCreated: DateTime

  """The date the element was last updated."""
  dateUpdated: DateTime
}

@codecov
Copy link

codecov bot commented Aug 28, 2019

Codecov Report

Merging #4834 into develop will decrease coverage by 0.03%.
The diff coverage is 0%.

Impacted file tree graph

@@              Coverage Diff              @@
##             develop    #4834      +/-   ##
=============================================
- Coverage       33.6%   33.57%   -0.04%     
- Complexity     13563    13573      +10     
=============================================
  Files            602      603       +1     
  Lines          40846    40884      +38     
=============================================
  Hits           13726    13726              
- Misses         27120    27158      +38
Impacted Files Coverage Δ Complexity Δ
src/console/controllers/GraphqlController.php 0% <0%> (ø) 10 <10> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26f8bf2...1ced338. Read the comment docs.

@pauloelias
Copy link

Awesome work @khalwat!

In addition to the 👍 I would also like to say this will be a huge help to our workflow since our headless CMS does not have devMode enabled. We still need to be able to test queries with the most up-to-date schema and I'd prefer not to have to fork this (now) huge database to a staging environment every time we update content models.

When we run headless we only spin up temporary review apps for each release but we don't need a long-running staging server in between releases because we don't need to worry about any frontend twig templates breaking.

Signed-off-by: Andrew Welch <andrew@nystudio107.com>
Signed-off-by: Andrew Welch <andrew@nystudio107.com>
@andris-sevcenko
Copy link
Contributor

You are a beautiful man and let noone tell you otherwise.

@andris-sevcenko andris-sevcenko merged commit 2b281df into craftcms:develop Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants