diff --git a/lib/potassium/recipes/front_end.rb b/lib/potassium/recipes/front_end.rb index 89cee2a4..70c2553d 100644 --- a/lib/potassium/recipes/front_end.rb +++ b/lib/potassium/recipes/front_end.rb @@ -88,36 +88,13 @@ def setup_jest def setup_apollo run 'bin/yarn add vue-apollo graphql apollo-client apollo-link apollo-link-http apollo-cache-inmemory graphql-tag' - apollo_imports = <<~HEREDOC - \n - import { ApolloClient } from 'apollo-client'; - import { createHttpLink } from 'apollo-link-http'; - import { InMemoryCache } from 'apollo-cache-inmemory'; - import VueApollo from 'vue-apollo'; - HEREDOC + inject_into_file( 'app/javascript/packs/application.js', apollo_imports, after: "import App from '../app.vue';" ) - apollo_loading = <<~HEREDOC - \n - const httpLink = createHttpLink({ - uri: `${window.location.origin}/graphql`, - }) - const cache = new InMemoryCache() - const apolloClient = new ApolloClient({ - link: httpLink, - cache, - }) - - Vue.use(VueApollo) - const apolloProvider = new VueApollo({ - defaultClient: apolloClient, - }) - HEREDOC - inject_into_file( 'app/javascript/packs/application.js', apollo_loading, @@ -141,6 +118,35 @@ def frameworks(framework) frameworks[framework] end + def apollo_imports + <<~JS + \n + import { ApolloClient } from 'apollo-client'; + import { createHttpLink } from 'apollo-link-http'; + import { InMemoryCache } from 'apollo-cache-inmemory'; + import VueApollo from 'vue-apollo'; + JS + end + + def apollo_loading + <<~JS + \n + const httpLink = createHttpLink({ + uri: `${window.location.origin}/graphql`, + }) + const cache = new InMemoryCache() + const apolloClient = new ApolloClient({ + link: httpLink, + cache, + }) + + Vue.use(VueApollo) + const apolloProvider = new VueApollo({ + defaultClient: apolloClient, + }) + JS + end + def setup_client_css application_css = 'app/javascript/css/application.css' create_file application_css, "", force: true