Last active
January 8, 2019 06:58
-
-
Save lili668668/f73797fe71672490590fa023d958bde8 to your computer and use it in GitHub Desktop.
Ads API 整合 GraphQL Schema Proposal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// refer to https://github.com/kdchang/reactjs101/blob/master/Appendix04/README.md | |
const facebookCampaignType = new graphql.GraphQLObjectType({ | |
name: 'FacebookCampaign', | |
fields: { | |
id: { type: graphql.GraphQLString }, | |
name: { type: graphql.GraphQLString }, | |
status: { type: graphql.GraphQLString }, | |
// other fields | |
} | |
}) | |
const googleCampaignType = new graphql.GraphQLObjectType({ | |
name: 'GoogleCampaign', | |
fields: { | |
id: { type: graphql.GraphQLString }, | |
name: { type: graphql.GraphQLString }, | |
status: { type: graphql.GraphQLString }, | |
// other fields | |
} | |
}) | |
const facebookInsightLevelEnumType = new graphql.GraphQLEnumType({ | |
name: 'FacebookInsightLevelEnum', | |
values: { | |
CAMPAIGN: { value: 0 }, | |
ADSET: { value: 1 }, | |
AD: { value: 2 } | |
} | |
}) | |
const googleInsightLevelEnumType = new graphql.GraphQLEnumType({ | |
name: 'GoogleInsightLevelEnum', | |
values: { | |
CAMPAIGN: { value: 0 }, | |
ADGROUP: { value: 1 }, | |
AD: { value: 2 } | |
} | |
}) | |
const facebookSummaryInsightType = new graphql.GraphQLObjectType({ | |
name: 'FacebookSummaryInsight', | |
fields: { | |
startDate: { type: graphql.GraphQLString }, | |
endDate: { type: graphql.GraphQLString }, | |
cost: { type: graphql.GraphQLFloat }, | |
clicks: { type: graphql.GraphQLFloat }, | |
impressions: { type: graphql.GraphQLFloat }, | |
ctr: { type: graphql.GraphQLFloat }, | |
// other fields | |
} | |
}) | |
const googleSummaryInsightType = new graphql.GraphQLObjectType({ | |
name: 'GoogleSummaryInsight', | |
fields: { | |
startDate: { type: graphql.GraphQLString }, | |
endDate: { type: graphql.GraphQLString }, | |
cost: { type: graphql.GraphQLFloat }, | |
clicks: { type: graphql.GraphQLFloat }, | |
impressions: { type: graphql.GraphQLFloat }, | |
ctr: { type: graphql.GraphQLFloat }, | |
// other fields | |
} | |
}) | |
const facebookInsightType = new graphql.GraphQLObjectType({ | |
name: 'FacebookInsight', | |
fields: { | |
startDate: { type: graphql.GraphQLString }, | |
endDate: { type: graphql.GraphQLString }, | |
campaignId: { type: graphql.GraphQLString }, | |
adsetId: { type: graphql.GraphQLString }, | |
adId: { type: graphql.GraphQLString }, | |
cost: { type: graphql.GraphQLFloat }, | |
clicks: { type: graphql.GraphQLFloat }, | |
impressions: { type: graphql.GraphQLFloat }, | |
ctr: { type: graphql.GraphQLFloat }, | |
// other fields | |
} | |
}) | |
const googleInsightType = new graphql.GraphQLObjectType({ | |
name: 'GoogleInsight', | |
fields: { | |
startDate: { type: graphql.GraphQLString }, | |
endDate: { type: graphql.GraphQLString }, | |
campaignId: { type: graphql.GraphQLString }, | |
adgroupId: { type: graphql.GraphQLString }, | |
adId: { type: graphql.GraphQLString }, | |
cost: { type: graphql.GraphQLFloat }, | |
clicks: { type: graphql.GraphQLFloat }, | |
impressions: { type: graphql.GraphQLFloat }, | |
ctr: { type: graphql.GraphQLFloat }, | |
// other fields | |
} | |
}) | |
const schema = new graphql.GraphQLSchema({ | |
query: new graphql.GraphQLObjectType({ | |
name: 'Query', | |
fields: { | |
facebookCampaign: { | |
type: graphql.GraphQLList<facebookCampaignType>, | |
args: { | |
accountId: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
accessToken: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
id: { type: graphql.GraphQLString }, | |
ids: { type: graphql.GraphQLList<graphql.GraphQLString> }, | |
searchByName: { type: graphql.GraphQLString } | |
}, | |
resolve: function (_, args) { | |
// do something... | |
} | |
}, | |
facebookAdset: { | |
// like as campaign | |
}, | |
facebookAd: { | |
// like as campaign | |
}, | |
facebookInsight: { | |
type: graphql.GraphQLList<facebookInsightType>, | |
args: { | |
accountId: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
accessToken: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
level: { type: facebookInsightLevelEnumType }, | |
datePreset: { type: graphql.GraphQLString }, | |
since: { type: graphql.GraphQLString }, | |
until: { type: graphql.GraphQLString }, | |
filterings: { type: graphql.GraphQLString }, | |
timeIncrement: { type: graphql.GraphQLString }, | |
breakdown: { type: graphql.GraphQLString }, | |
// other queries | |
}, | |
resolve: function (_, args) { | |
// do something... | |
} | |
}, | |
facebookSummaryInsight: { | |
type: graphql.GraphQLList<facebookSummaryInsightType>, | |
args: { | |
accountId: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
accessToken: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
level: { type: facebookInsightLevelEnumType }, | |
datePreset: { type: graphql.GraphQLString }, | |
since: { type: graphql.GraphQLString }, | |
until: { type: graphql.GraphQLString }, | |
filterings: { type: graphql.GraphQLString }, | |
// other queries | |
}, | |
resolve: function (_, args) { | |
// do something... | |
} | |
}, | |
googleCampaign: { | |
type: graphql.GraphQLList<googleCampaignType>, | |
args: { | |
accountId: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
refreshToken: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
id: { type: graphql.GraphQLString }, | |
ids: { type: graphql.GraphQLList<graphql.GraphQLString> }, | |
searchByName: { type: graphql.GraphQLString } | |
}, | |
resolve: function (_, args) { | |
// do something... | |
} | |
}, | |
googleAdGroup: { | |
// like as campaign | |
}, | |
googleAd: { | |
// like as campaign | |
}, | |
googleInsight: { | |
type: graphql.GraphQLList<googleInsightType>, | |
args: { | |
accountId: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
refreshToken: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
level: { type: googleInsightLevelEnumType }, | |
since: { type: graphql.GraphQLString }, | |
until: { type: graphql.GraphQLString }, | |
filterings: { type: graphql.GraphQLString }, | |
segment: { type: graphql.GraphQLString }, | |
// other queries | |
}, | |
resolve: function (_, args) { | |
// do something... | |
} | |
}, | |
googleSummaryInsight: { | |
type: graphql.GraphQLList<googleSummaryInsightType>, | |
args: { | |
accountId: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
refreshToken: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
level: { type: googleInsightLevelEnumType }, | |
since: { type: graphql.GraphQLString }, | |
until: { type: graphql.GraphQLString }, | |
filterings: { type: graphql.GraphQLString }, | |
// other queries | |
}, | |
resolve: function (_, args) { | |
// do something... | |
} | |
} | |
} | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// refer to https://github.com/kdchang/reactjs101/blob/master/Appendix04/README.md | |
const campaignType = new graphql.GraphQLObjectType({ | |
name: 'Campaign', | |
fields: { | |
id: { type: graphql.GraphQLString }, | |
name: { type: graphql.GraphQLString }, | |
status: { type: graphql.GraphQLString }, | |
// other fields | |
} | |
}) | |
const insightLevelEnumType = new graphql.GraphQLEnumType({ | |
name: 'InsightLevelEnum', | |
values: { | |
CAMPAIGN: { value: 0 }, | |
ADSET: { value: 1 }, // facebook | |
ADGROUP: { value: 2 }, // google | |
AD: { value: 3 }, | |
KEYWORD: { value: 4 } // a special level for google keyword insight | |
} | |
}) | |
const insightType = new graphql.GraphQLObjectType({ | |
name: 'Insight', | |
fields: { | |
startDate: { type: graphql.GraphQLString }, | |
endDate: { type: graphql.GraphQLString }, | |
campaignId: { type: graphql.GraphQLString }, | |
adsetId: { type: graphql.GraphQLString }, | |
adId: { type: graphql.GraphQLString }, | |
cost: { type: graphql.GraphQLFloat }, | |
clicks: { type: graphql.GraphQLFloat }, | |
impressions: { type: graphql.GraphQLFloat }, | |
ctr: { type: graphql.GraphQLFloat }, | |
// other fields includes facebook insight fields and google insight fields | |
} | |
}) | |
const schema = new graphql.GraphQLSchema({ | |
query: new graphql.GraphQLObjectType({ | |
name: 'Query', | |
fields: { | |
campaign: { | |
type: graphql.GraphQLList<campaignType>, | |
args: { | |
accountId: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
id: { type: graphql.GraphQLString }, | |
ids: { type: graphql.GraphQLList<graphql.GraphQLString> }, | |
searchByName: { type: graphql.GraphQLString } | |
}, | |
resolve: function (_, args) { | |
// do something... | |
} | |
}, | |
adset: { | |
// like as campaign | |
}, | |
adGroup: { | |
// like as campaign | |
}, | |
ad: { | |
// like as campaign | |
}, | |
insight: { | |
type: graphql.GraphQLList<insightType>, | |
args: { | |
accountId: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
accessToken: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
level: { type: facebookInsightLevelEnumType }, | |
datePreset: { type: graphql.GraphQLString }, | |
since: { type: graphql.GraphQLString }, | |
until: { type: graphql.GraphQLString }, | |
filter: { type: graphql.GraphQLString }, | |
breakdown: { type: graphql.GraphQLString }, | |
// other queries | |
}, | |
resolve: function (_, args) { | |
// do something... | |
} | |
}, | |
summary: { | |
type: graphql.GraphQLList<insightType>, | |
args: { | |
accountId: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
accessToken: { type: graphql.GraphQLNonNull<graphql.GraphQLString> }, | |
level: { type: facebookInsightLevelEnumType }, | |
datePreset: { type: graphql.GraphQLString }, | |
since: { type: graphql.GraphQLString }, | |
until: { type: graphql.GraphQLString }, | |
filter: { type: graphql.GraphQLString }, | |
// other queries | |
}, | |
resolve: function (_, args) { | |
// do something... | |
} | |
} | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment