Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. const Customer = new GraphQLObjectType({
  2. description: 'Customer data schema',
  3. name: 'Customer',
  4. fields: () => ({
  5. name: {
  6. type: GraphQLString,
  7. sqlColumn: 'NAME',
  8. },
  9. city: {
  10. type: GraphQLString,
  11. sqlColumn: 'CITY'
  12. },
  13. country: {
  14. type: GraphQLString,
  15. sqlColumn: 'COUNTRY'
  16. },
  17. gender: {
  18. type: GraphQLString,
  19. sqlColumn: 'GENDER'
  20. },
  21. emp_id: {
  22. type: GraphQLString,
  23. sqlColumn: 'EMP_ID'
  24. }
  25. })
  26. });
  27.  
  28. Customer._typeConfig = {
  29. sqlTable: 'CUSTOMER',
  30. uniqueKey: ['NAME','EMP_ID']
  31. }
  32.  
  33. const QueryRoot = new GraphQLObjectType({
  34. description: 'global query object',
  35. name: 'RootQuery',
  36. fields: () => ({
  37. customer: {
  38. type: new GraphQLList(Customer),
  39. args: {
  40. emp_id: {
  41. description: 'Emp Id',
  42. type: GraphQLString
  43. },
  44. name: {
  45. description: 'Customer Name',
  46. type: GraphQLString
  47. }
  48. },
  49. where: (customer, args, context) => {
  50. return `${customer}."EMP_ID" = :emp_id AND ${customer}."NAME" = :name`;
  51. },
  52. resolve: (parent, args, context, resolveInfo) => {
  53. return joinMonster(resolveInfo, context, sql => {
  54. console.log('joinMaster', sql);
  55. return database.simpleExecute(sql, args,{
  56. outFormat: database.OBJECT
  57. });
  58. });
  59. }
  60. }
  61. })
  62. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement