Fix session variable bug

This commit is contained in:
Vikram Rangnekar 2019-09-09 00:02:25 -04:00
parent 78dbe32bd4
commit 58eb272df0
3 changed files with 34 additions and 24 deletions

View File

@ -23,23 +23,24 @@ COPY --from=react-build /web/build/ ./web/build/
ENV GO111MODULE=on ENV GO111MODULE=on
RUN go mod vendor RUN go mod vendor
RUN go generate ./... && \ RUN go generate ./... && \
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o service && \ CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o super-graph && \
upx --ultra-brute -qq service && \ upx --ultra-brute -qq super-graph && \
upx -t service upx -t super-graph
# stage: 3 # stage: 3
FROM alpine:latest FROM alpine:latest
WORKDIR /app WORKDIR /
RUN apk add --no-cache tzdata RUN apk add --no-cache tzdata
RUN mkdir -p /config
COPY --from=go-build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=go-build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=go-build /app/service . COPY --from=go-build /app/config/* /config/
COPY --from=go-build /app/config/* ./ COPY --from=go-build /app/super-graph .
RUN chmod +x /app/service RUN chmod +x /super-graph
USER nobody USER nobody
EXPOSE 8080 EXPOSE 8080
CMD ./service CMD ./super-graph

View File

@ -1,17 +1,5 @@
# http://localhost:8080/ # http://localhost:8080/
query {
customers {
id
email
payments {
customer_id
amount
billing_details
}
}
}
query { query {
products(id: $PRODUCT_ID) { products(id: $PRODUCT_ID) {
name name
@ -59,6 +47,15 @@ mutation {
} }
} }
variables {}
{
me {
id
email
}
}
variables { variables {
"update": { "update": {
@ -83,3 +80,17 @@ query {
} }
} }
variables {}
query {
customers {
id
email
payments {
customer_id
amount
billing_details
}
}
}

View File

@ -269,7 +269,7 @@ func (c *coreContext) resolvePreparedSQL(gql string) ([]byte, *preparedItem, err
defer tx.Rollback() defer tx.Rollback()
if v := c.Value(userIDKey); v != nil { if v := c.Value(userIDKey); v != nil {
_, err = tx.Exec(`SET LOCAL SESSION "user.id" = ?`, v) _, err = tx.Exec(`SET LOCAL "user.id" = ?`, v)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -285,8 +285,6 @@ func (c *coreContext) resolvePreparedSQL(gql string) ([]byte, *preparedItem, err
return nil, nil, err return nil, nil, err
} }
// w.WriteString(`SET LOCAL SESSION "user.id" = '{{user_id}}'; `)
fmt.Printf("PRE: %v\n", ps.stmt) fmt.Printf("PRE: %v\n", ps.stmt)
return []byte(root), ps, nil return []byte(root), ps, nil
@ -341,7 +339,7 @@ func (c *coreContext) resolveSQL(qc *qcode.QCode) (
defer tx.Rollback() defer tx.Rollback()
if v := c.Value(userIDKey); v != nil { if v := c.Value(userIDKey); v != nil {
_, err = tx.Exec(`SET LOCAL SESSION "user.id" = ?`, v) _, err = tx.Exec(`SET LOCAL "user.id" = ?`, v)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err