The "/graphql" function is not imported

Hi all,

I am developping on Redwood and when on my laptop:

yarn redwood dev

[...]
api | Importing Server Functions... 
api | /graphql 2100 ms
api | /extracts 13 ms
api | /healthcheck 9 ms
api | /stripe 11 ms
api | /upload 1 ms
api | ...Done importing in 2139 ms
api | Took 2191 ms
api | API listening on http://localhost:8911/
api | GraphQL endpoint at /graphql
api | 16:22:42 🌲 Server listening at http://[::]:8911
[...]

I reproduced all the same steps I make (build,…) in a Dockerfile, and when running that image with docker run having yarn redwood dev in the entrypoint.sh file, I get:

[...]
api | Importing Server Functions... 
api | /extracts 16 ms
api | /healthcheck 2 ms
api | /upload 1 ms
api | Took 1413 ms
api | API listening on http://localhost:8911/
api | GraphQL endpoint at /graphql
api | 14:26:57 🌲 Server listening at http://[::]:8911
[...]

The problem here is that the api | /graphql 2100 ms line is missing once in Docker: The /graphql function is not imported.

Note that the migration is happening right (tables created)

What could be the problem? Where to have a look?

First place you’ll want to look is in your redwood.toml file. I also recommend checking out the docs about what redwood.toml is for. What is your apiUrl set to?

When I use Docker I have it point to http://localhost:8911/api like so:

[web]
  title = "Redwood App"
  port = 8910
  apiUrl = "http://localhost:8911/api"
[api]
  port = 8911

I then include the following in my API Dockerfile.

ENTRYPOINT [ "yarn", "rw", "serve", "api", "--port", "8911", "--rootPath", "/api" ]

More context in this article if what I just said doesn’t make sense:

1 Like

Thank you,
I see you splat it to two containers.
I try this.

You are then confirming it is normal that /graphql is not imported if I am doing things that way?

With this configuration your GraphQL endpoint will be exposed on localhost:8911/api/graphql and you can test whether it is working with the following curl command:

curl \
  --request POST \
  --header 'content-type: application/json' \
  --url 'http://localhost:8911/api/graphql' \
  --data '{"query":"{ redwood { version } }"}'

Also it is possible to do this with a single Docker file. If you follow this Fly example, after running flyctl launch you will have a Dockerfile automatically generated for your project.

ARG BASE_IMAGE=node:16.13.0-alpine
FROM ${BASE_IMAGE} as base

RUN mkdir /app
WORKDIR /app

# Required for building the api and web distributions
ENV NODE_ENV development

FROM base as dependencies

COPY .yarn .yarn
COPY .yarnrc.yml .yarnrc.yml
COPY package.json package.json
COPY web/package.json web/package.json
COPY api/package.json api/package.json
COPY yarn.lock yarn.lock

RUN --mount=type=cache,target=/root/.yarn/berry/cache \
    --mount=type=cache,target=/root/.cache yarn install --immutable

COPY redwood.toml .
COPY graphql.config.js .

FROM dependencies as web_build

COPY web web
RUN yarn rw build web

FROM dependencies as api_build

COPY api api
RUN yarn rw build api

FROM dependencies

ENV NODE_ENV production

COPY --from=web_build /app/web/dist /app/web/dist
COPY --from=api_build /app/api /app/api
COPY --from=api_build /app/node_modules/.prisma /app/node_modules/.prisma

COPY .fly .fly

ENTRYPOINT ["sh"]
CMD [".fly/start.sh"]

This autogenerated file likely won’t work perfectly for your app if you just copy and paste it. But it might be usable with some slight modifications.

1 Like