Skip to content

Commit

Permalink
refactor(gql): move apollo herdocs to methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ironcadiz committed Jan 11, 2021
1 parent 3e106fc commit dc823c6
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions lib/potassium/recipes/front_end.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit dc823c6

Please sign in to comment.