Skip to content

Commit

Permalink
ex nihilo
Browse files Browse the repository at this point in the history
  • Loading branch information
el-schneider committed Mar 29, 2022
0 parents commit 29f60eb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
vendor
mix-manifest.json
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Graphql Svg String

**Graphql Svg String** is a Statamic addon that adds a field `svgString` to an `AssetInterface`, which – you guessed it – returns the SVG as a string.

## How to Install

You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root:

```bash
composer require el-schneider/graphql-svg-string
```
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "el-schneider/graphql-svg-string",
"autoload": {
"psr-4": {
"ElSchneider\\GraphqlSvgString\\": "src"
}
},
"extra": {
"statamic": {
"name": "Graphql Svg String",
"description": "Graphql Svg String addon"
},
"laravel": {
"providers": [
"ElSchneider\\GraphqlSvgString\\ServiceProvider"
]
}
}
}
29 changes: 29 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace ElSchneider\GraphqlSvgString;

use Statamic\Facades\GraphQL;
use Statamic\Assets\Asset;
use Statamic\Providers\AddonServiceProvider;

class ServiceProvider extends AddonServiceProvider
{
public function bootAddon()
{
GraphQL::addField(
"AssetInterface",
'svgString',
function () {
return [
"type" => GraphQL::type('String'),
"resolve" => function (Asset $asset) {
if ($asset->extension() === 'svg') {
return $asset->contents();
}
return null;
}
];
}
);
}
}

0 comments on commit 29f60eb

Please sign in to comment.