Skip to content

Instantly share code, notes, and snippets.

View gottfrois's full-sized avatar

Pierre-Louis Gottfrois gottfrois

View GitHub Profile
@gottfrois
gottfrois / iex.ex
Created April 13, 2020 10:04
Code snippet in Stream Paginated GraphQL API in Elixir medium blog post
"""
query ListRecords($first: Int){
records(first: $first) {
edges {
node {
id
}
}
}
}
@gottfrois
gottfrois / stream_paginator.ex
Last active April 13, 2020 10:01
Code snippet in Stream Paginated GraphQL API in Elixir medium blog post
defmodule MyApp.StreamPaginator do
def stream(query, args \\ %{first: 100}) do
init = fn -> request(query, args) end
next = &next/1
stop = &Function.identity/1
Stream.resource(init, next, stop)
end
defp request(query, args) do
@gottfrois
gottfrois / stream_paginator.ex
Created April 13, 2020 09:56
Code snippet in Stream Paginated GraphQL API in Elixir medium blog post
defp next({nil, _query, _args} = acc), do: {:halt, acc}
defp next({%{"hasNextPage" => false}, _query, _args} = acc), do: {:halt, acc}
@gottfrois
gottfrois / stream_paginator.ex
Last active April 13, 2020 10:01
Code snippet in Stream Paginated GraphQL API in Elixir medium blog post
defmodule MyApp.StreamPaginator do
def stream(query, args \\ %{first: 100}) do
# ...
next = &next/1
# ...
end
# ...
@gottfrois
gottfrois / stream_paginator.ex
Last active April 13, 2020 10:01
Code snippet in Stream Paginated GraphQL API in Elixir medium blog post
defmodule MyApp.StreamPaginator do
def stream(query, args \\ %{first: 100}) do
init = fn -> request(query, args) end
next = fn -> nil end
stop = fn -> nil end
Stream.resource(init, next, stop)
end
defp request(query, args) do
@gottfrois
gottfrois / stream_paginator.ex
Last active April 13, 2020 10:02
Code snippet in Stream Paginated GraphQL API in Elixir medium blog post
defmodule MyApp.StreamPaginator do
def stream(query, args \\ %{first: 100}) do
init = fn -> end
next = fn -> end
stop = fn -> end
Stream.resource(init, next, stop)
end
end
@gottfrois
gottfrois / query.gql
Last active April 13, 2020 09:41
Code snippet in Stream Paginated GraphQL API in Elixir medium blog post
query {
records(first: 100) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
id
}
@gottfrois
gottfrois / Dockerfile
Created September 6, 2018 09:06
medium-multi-stage-dockerfile-final-dockerfile
###############################
# Stage wkhtmltopdf
FROM madnight/docker-alpine-wkhtmltopdf as wkhtmltopdf
######################
# Stage: ruby
FROM ruby:2.5.1-alpine3.7 as ruby
LABEL description="Base ruby image used by other stages"
######################
@gottfrois
gottfrois / Dockerfile
Created September 6, 2018 09:03
medium-multi-stage-dockerfile-wkhtmltopdf-stage
###############################
# Stage wkhtmltopdf
FROM madnight/docker-alpine-wkhtmltopdf as wkhtmltopdf
@gottfrois
gottfrois / Dockerfile
Created September 6, 2018 09:02
medium-multi-stage-dockerfile-release-stage
###############################
# Stage release
FROM runner as release
LABEL description="Builds a release image removing unneeded files and dependencies"
# Removes development and test gems by re-running the bundle
# install command using cached gems and simply removing unneeded
# gems using the clean option.
RUN bundle install --local --clean --without development test \
# Remove unneeded cached gems