2019-11-25 08:22:33 +01:00
|
|
|
package qcode
|
|
|
|
|
|
|
|
func GetQType(gql string) QType {
|
2020-04-16 06:26:32 +02:00
|
|
|
ic := false
|
2019-11-25 08:22:33 +01:00
|
|
|
for i := range gql {
|
|
|
|
b := gql[i]
|
2020-04-16 06:26:32 +02:00
|
|
|
switch {
|
|
|
|
case b == '#':
|
|
|
|
ic = true
|
|
|
|
case b == '\n':
|
|
|
|
ic = false
|
|
|
|
case !ic && b == '{':
|
2019-11-25 08:22:33 +01:00
|
|
|
return QTQuery
|
2020-04-16 06:26:32 +02:00
|
|
|
case !ic && al(b):
|
2019-11-25 08:22:33 +01:00
|
|
|
switch b {
|
|
|
|
case 'm', 'M':
|
|
|
|
return QTMutation
|
|
|
|
case 'q', 'Q':
|
|
|
|
return QTQuery
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
func al(b byte) bool {
|
|
|
|
return (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9')
|
|
|
|
}
|
2020-04-10 08:27:43 +02:00
|
|
|
|
|
|
|
func (qt QType) String() string {
|
|
|
|
switch qt {
|
|
|
|
case QTQuery:
|
|
|
|
return "query"
|
|
|
|
case QTMutation:
|
|
|
|
return "mutation"
|
|
|
|
case QTInsert:
|
|
|
|
return "insert"
|
|
|
|
case QTUpdate:
|
|
|
|
return "update"
|
|
|
|
case QTDelete:
|
|
|
|
return "delete"
|
|
|
|
case QTUpsert:
|
|
|
|
return "upsert"
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|