8000 fix minify jm issues by bueche · Pull Request #514 · join-monster/join-monster · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix minify jm issues #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### vNEXT

### v3.3.3 (March 25, 2024)
#### Fixed
- [#514](https://github.com/join-monster/join-monster/pull/514): Fix of minify issues that cause production builds of react native to fail.

### v3.3.2 (August 27, 2023)
#### Fixed
- [#506](https://github.com/join-monster/join-monster/pull/506): Removed use of dynamic require which was preventing join-monster deployments with react native. Tested with expo-sqlite on Android (outside of this environment).
Expand Down
58 changes: 42 additions & 16 deletions src/query-ast-to-sql-ast/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import {
sortKeyColumns
} from '../util'

import {
isObjectType,
isUnionType,
isInterfaceType,
isListType,
isNonNullType,
isScalarType,
} from "graphql"

class SQLASTNode {
constructor(parentNode, props) {
Object.defineProperty(this, 'parent', {
Expand All @@ -27,6 +36,30 @@ class SQLASTNode {
}
}

// any value here needs to be paired with an instance type checking function from graphql in isOneOfGraphQLTypes()
const ALL_TYPES_TO_CHECK = new Set(['GraphQLObjectType',
'GraphQLUnionType',
'GraphQLInterfaceType',
'GraphQLList',
'GraphQLNonNull',
'GraphQLScalarType'])


function isOneOfGraphQLTypes(instance, typeStringArray) {
let returnVal = false
typeStringArray.forEach(typeString => {
if (typeString === 'GraphQLObjectType' && isObjectType(instance)) returnVal = true
if (typeString === 'GraphQLUnionType' && isUnionType(instance)) returnVal = true
if (typeString === 'GraphQLInterfaceType' && isInterfaceType(instance)) returnVal = true
if (typeString === 'GraphQLList' && isListType(instance)) returnVal = true
if (typeString === 'GraphQLNonNull' && isNonNullType(instance)) returnVal = true
if (typeString === 'GraphQLScalarType' && isScalarType(instance)) returnVal = true
if (!ALL_TYPES_TO_CHECK.has(typeString)) {
throw new Error('unexpected input to isOneOfGraphQLTypes()')
}
})
return returnVal
}
// an enumeration of all the types that can map to SQL tables
const TABLE_TYPES = [
'GraphQLObjectType',
Expand Down Expand Up @@ -167,14 +200,14 @@ export function populateASTNode(
sqlASTNode.args = getArgumentValues(field, queryASTNode, this.variableValues)

// if list then mark flag true & get the type inside the GraphQLList container type
if (gqlType.constructor.name === 'GraphQLList') {
if (isOneOfGraphQLTypes(gqlType, ['GraphQLList'])) {
gqlType = stripNonNullType(gqlType.ofType)
grabMany = true
}

// if its a relay connection, there are several things we need to do
if (
gqlType.constructor.name === 'GraphQLObjectType' &&
isOneOfGraphQLTypes(gqlType, ['GraphQLObjectType']) &&
gqlType._fields.edges &&
gqlType._fields.pageInfo
) {
Expand Down Expand Up @@ -212,7 +245,7 @@ export function populateASTNode(
// is this a table in SQL?
if (
!fieldConfig.ignoreTable &&
TABLE_TYPES.includes(gqlType.constructor.name) &&
isOneOfGraphQLTypes(gqlType, TABLE_TYPES) &&
config.sqlTable
) {
if (depth >= 1) {
Expand Down Expand Up @@ -258,9 +291,7 @@ export function populateASTNode(
// see enablePluginsForSchemaResolvers function: apollo-server issue #3988
} else if (
fieldConfig.sqlColumn ||
['GraphQLObjectType', 'GraphQLInterfaceType'].includes(
parentTypeNode.constructor.name
)
isOneOfGraphQLTypes(parentTypeNode, ['GraphQLObjectType', 'GraphQLInterfaceType'])
) {
sqlASTNode.type = 'column'
sqlASTNode.name = fieldConfig.sqlColumn || field.name
Expand Down Expand Up @@ -430,9 +461,7 @@ function handleTable(
// its been generalized to `alwaysFetch`, as its a useful feature for more than just unions
if (
config.typeHint &&
['GraphQLUnionType', 'GraphQLInterfaceType'].includes(
gqlType.constructor.name
)
isOneOfGraphQLTypes(gqlType, ['GraphQLUnionType', 'GraphQLInterfaceType'])
) {
deprecate('`typeHint` is deprecated. Use `alwaysFetch` instead.')
children.push(columnToASTChild(config.typeHint, namespace))
Expand All @@ -445,8 +474,7 @@ function handleTable(

if (queryASTNode.selectionSet) {
if (
gqlType.constructor.name === 'GraphQLUnionType' ||
gqlType.constructor.name === 'GraphQLInterfaceType'
isOneOfGraphQLTypes(gqlType, ['GraphQLUnionType', 'GraphQLInterfaceType'])
) {
// union types have special rules for the child fields in join monster
sqlASTNode.type = 'union'
Expand Down Expand Up @@ -527,8 +555,7 @@ function handleUnionSelections(
// but the gqlType is the Union. The data isn't there, its on each of the types that make up the union
// lets find that type and handle the selections based on THAT type instead
const deferredType = this.schema._typeMap[selectionNameOfType]
const deferToObjectType =
deferredType.constructor.name === 'GraphQLObjectType'
const deferToObjectType = isOneOfGraphQLTypes(deferredType, ['GraphQLObjectType'])
const handler = deferToObjectType
? handleSelections
: handleUnionSelections
Expand Down Expand Up @@ -559,8 +586,7 @@ function handleUnionSelections(
const fragment = this.fragments[fragmentName]
const fragmentNameOfType = fragment.typeCondition.name.value
const deferredType = this.schema._typeMap[fragmentNameOfType]
const deferToObjectType =
deferredType.constructor.name === 'GraphQLObjectType'
const deferToObjectType = isOneOfGraphQLTypes(deferredType, ['GraphQLObjectType'])
const handler = deferToObjectType
? handleSelections
: handleUnionSelections
Expand Down Expand Up @@ -782,7 +808,7 @@ function stripRelayConnection(gqlType, queryASTNode, fragments) {
}

function stripNonNullType(type) {
return type.constructor.name === 'GraphQLNonNull' ? type.ofType : type
return isOneOfGraphQLTypes(type, ['GraphQLNonNull']) ? type.ofType : type
}

// go through and make sure se only ask for each sqlDep once per table
Expand Down
0