virtualirfan
04/27/2018, 12:41 AMget-graphql-schema
on the relay endpoint currently skips the subscription schema but it is returned for the simple API endpoint. I can't just copy paste the subscription schema sections into the relay schema because of missing types and general incompatibility between the two. What's a way to deal with this? I don't mind generating the missing subscription types/inputs via a script but I need help seeing what that should look like.
Note: I'm OK switching to prisma at some point but can't do it just yet.
Note: I'm aware of the discussion in https://github.com/graphcool/graphcool-framework/issues/85 and https://www.graph.cool/forum/t/relay-modern-subscriptions/420/7 but neither of those provides any details on how to go about converting to a relay schema from simple.virtualirfan
04/27/2018, 1:54 AMnilan
04/27/2018, 4:00 AMvirtualirfan
04/27/2018, 4:32 AMThat example schema does not include <TypeName>SubscriptionFilter and <TypeName>SubscriptionFilterNode input specs. Why is that? Aren't those needed to specify filters on the fields to use for subscriptions?
nilan
04/27/2018, 4:36 AMnilan
04/27/2018, 4:36 AMvirtualirfan
04/27/2018, 5:17 AM#!/bin/bash
export RELAY_IN_FILE="./data/schema.relay.graphql"
export SIMPLE_IN_FILE="./data/schema.simple.graphql"
export TYPES_OUT_FILE="./data/schema.subscription.lower.graphql"
export FINAL_SCHEMA_FILE="./data/schema.graphql"
export GEN_TYPES="./scripts/genLowerRelayTypesFromSimple"
export GET_SCHEMA="get-graphql-schema"
if [ -z ${SRI_APP_RELAY_URL+x} ]; then
echo "ERROR: Must specify relay URL in variable \$SRI_APP_RELAY_URL"
exit 1
fi
# Download latest relay schema
${GET_SCHEMA} $SRI_APP_RELAY_URL > ${RELAY_IN_FILE}
if [ "$?" -ne "0" ]; then
echo "ERROR: Could not download latest relay schema from: " $SRI_APP_RELAY_URL
exit 1
fi
# construct matching URL but for the simple API instead
export SRI_APP_SIMPLE_URL=`echo ${SRI_APP_RELAY_URL} | sed s/relay/simple/`
# Download latest simple schema
${GET_SCHEMA} ${SRI_APP_SIMPLE_URL} > ${SIMPLE_IN_FILE}
if [ "$?" -ne "0" ]; then
echo "ERROR: Could not download latest simple schema from: " $SRI_APP_SIMPLE_URL
exit 1
fi
${GEN_TYPES} ${SIMPLE_IN_FILE} > ${TYPES_OUT_FILE}
if [ "$?" -ne "0" ]; then
echo "ERROR: Could not parse the simple schema lower types."
exit 1
fi
# combine subscription types with relay schema
cat ${RELAY_IN_FILE} ${TYPES_OUT_FILE} > ${FINAL_SCHEMA_FILE}
The genLowerRelayTypesFromSimple
file referred to above is:
#!/usr/bin/awk -f
BEGIN { RS="}";} \
/^\n\ntype.*PreviousValues |^\n\n(type|input).*Subscription(Filter((Node)*)|Payload)* / \
{print $0RS} \
END { \
print "\n\nenum _ModelMutationType {"; \
print " CREATED"; \
print " UPDATED"; \
print " DELETED"; \
print "}"; \
}
These are tested on a mac os x with the standard awk
that ships with Darwin. YMMV.nilan
04/27/2018, 5:25 AM