diff --git a/README.md b/README.md old mode 100644 new mode 100755 index a67d7e1..3cc710b --- a/README.md +++ b/README.md @@ -137,8 +137,9 @@ then run 1. ``CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';`` 2. ``GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;`` 3. ``flush privileges;`` - More information https://dev.mysql.com/doc/refman/5.5/en/adding-users.html +4. Set environment variable BIOM_MASS that holds user's password + ``export BIOM_MASS="password"`` load_local_database.py script needs mysql.connect module. diff --git a/database.py b/database.py index e267010..327516a 100644 --- a/database.py +++ b/database.py @@ -1,62 +1,254 @@ +# Calls to obtain values from database -# Calls to obtain values from the data structures (to be populated by the local database next) +import mysql.connector +from mysql.connector import pooling +import os +import schema +import dbqueries -import const +# increments key for aggregations def add_key_increment(dictionary, key): if not key in dictionary: dictionary[key]=0 dictionary[key]+=1 class Data(object): - def load_data(self): - self.data = const.DB() - def get_current_projects(self): - self.load_data() - return [self.get_project(project_id) for project_id in self.data.CURRENT_PROJECTS.keys()] + def __init__(self): + + self.conn_pool=mysql.connector.connect(use_pure=False, pool_name="portal", + pool_size=15, + pool_reset_session=True, + database='portal_ui', + user='biom_mass', + password=os.environ['BIOM_MASS']) + # holds projects info + self.projects={} + + def __exit__(self): + try: + self.conn_pool.close() + except: + print("No connection to close") + + # get connection from pool + def get_pool(self): + conn = mysql.connector.connect(pool_name="portal") + cursor = conn.cursor(buffered=True,dictionary=True) + return conn, cursor + + # release connection back to pool + def release_pool(self,conn,cursor): + cursor.close() + conn.close() + + + # runs query and returns result + def fetch_results(self,cursor,query): + cursor.execute(query) + return [row for row in cursor] + + + # get all projects from db + def get_current_projects(self): + conn,cursor=self.get_pool() + projects_data=self.fetch_results(cursor,dbqueries.projects_query) + project_object=[] + for project in projects_data: + getproject=self.get_project(project['id'],cursor) + self.projects[str(project['id'])]=getproject + project_object.append(getproject) + self.release_pool(conn,cursor) + return project_object + + # get user (currently none) def get_user(self): - self.load_data() - return self.data.CURRENT_USER + return schema.User(username="null") + + # get current version from db + def get_current_version(self): + conn,cursor=self.get_pool() + version_data=self.fetch_results(cursor,dbqueries.version_query) + self.release_pool(conn,cursor) + del version_data[0]['updated'] + del version_data[0]['id'] + return version_data[0] + + + # get project object details from db + def get_project(self,id,cursor): + + project_data=self.fetch_results(cursor,dbqueries.project_query(id)) + project_id=project_data[0]['project_id'] + proj_counts_data=self.fetch_results(cursor,dbqueries.project_counts_query(project_id)) + + return schema.Project( + id=id, + project_id=project_id, + name=project_data[0]['name'], + program=schema.Program(name=project_data[0]['program']), + summary=schema.Summary( + case_count=proj_counts_data[1]['total'], + file_count=proj_counts_data[0]['total'], + data_categories=self.get_data_categories("project",project_id,cursor), + experimental_strategies=self.get_experimental_strategies("project",project_id,cursor), + file_size=proj_counts_data[2]['total']), + primary_site=[project_data[0]['primary_site']]) + + + # get data categories file and case counts from db for a project or a participant + def get_data_categories(self,table,id,cursor): + + data_cat_data=self.fetch_results(cursor,dbqueries.data_cat_query(table,id)) + data_cat=[] + for item in data_cat_data: + count_data=self.fetch_results(cursor,dbqueries.data_cat_counts_query(table,id,item['data_category'])) + + data_cat.append( + schema.DataCategories( + case_count=count_data[1]['total'], + file_count=count_data[0]['total'], + data_category=item['data_category'])) + + return data_cat + - def get_project(self,id): - self.load_data() - return self.data.CURRENT_PROJECTS[id] + # get experimental strategies file count from db for a project + def get_experimental_strategies(self,table,id,cursor): + exp_str_data=self.fetch_results(cursor,dbqueries.exp_str_query(table,id)) + exp_str=[] + for item in exp_str_data: + count_data=self.fetch_results(cursor,dbqueries.exp_str_counts_query(table,id,item['experimental_strategy'])) + exp_str.append( + schema.ExperimentalStrategies( + case_count=count_data[1]['total'], + file_count=count_data[0]['total'], + experimental_strategy=item['experimental_strategy'])) + + + return exp_str + + + # get details of file object from db def get_file(self,id): - self.load_data() - return self.data.TEST_FILES[id] + conn,cursor=self.get_pool() + file_data=self.fetch_results(cursor,dbqueries.file_query(id)) + + file_object=schema.File( + id=id, + name=file_data[0]['file_name'], + participant=file_data[0]['participant'], + sample=file_data[0]['sample'], + access=file_data[0]['access'], + file_size=file_data[0]['file_size'], + data_category=file_data[0]['data_category'], + data_format=file_data[0]['data_format'], + platform=file_data[0]['platform'], + experimental_strategy=file_data[0]['experimental_strategy'], + file_name=file_data[0]['file_name'], + cases=schema.FileCases( + hits=[schema.FileCase( + file_data[0]['part_id'], + case_id=file_data[0]['participant'], + project=self.projects[str(file_data[0]['p_id'])], + demographic=schema.Demographic("not hispanic or latino","male","white"), + metadata_participant=schema.MetadataParticipant( + file_data[0]['part_id'], + file_data[0]['participant'], + file_data[0]['age_2012'], + file_data[0]['totMETs1'], + file_data[0]['weight_lbs']), + primary_site=[file_data[0]['primary_site']])]), + file_id=file_data[0]['file_id']) + + self.release_pool(conn,cursor) + return file_object + + + # get annotations (currently not in use) def get_case_annotation(self): - self.load_data() - return self.data.CURRENT_CASE_ANNOTATION + return schema.CaseAnnotation() + # get ids of all files from db def get_current_files(self): - self.load_data() - return self.data.CURRENT_FILES + conn,cursor=self.get_pool() + files_data=self.fetch_results(cursor,dbqueries.files_query) + self.release_pool(conn,cursor) + return schema.Files(hits=[file['id'] for file in files_data]) + # get ids of all cases from db def get_current_cases(self): - self.load_data() - return self.data.CURRENT_CASES + conn,cursor=self.get_pool() + cases_data=self.fetch_results(cursor, dbqueries.cases_query) + self.release_pool(conn,cursor) + return schema.RepositoryCases(hits=[case['id'] for case in cases_data]) + # get details of case object from db def get_case(self,id): - self.load_data() - return self.data.TEST_CASES[id] - def get_project_aggregations(self, projects): - import schema + # get entity_participant_id and file info from db + conn,cursor=self.get_pool() + case_data=self.fetch_results(cursor,dbqueries.case_query(id)) + part_id=case_data[0]['entity_participant_id'] + counts_data=self.fetch_results(cursor,dbqueries.case_counts_query(part_id)) + proj_data=self.fetch_results(cursor,dbqueries.case_project_query(part_id)) + proj_id=proj_data[0]['p_id'] + + # query to get metadata from prticipant table + metadata_part_data=self.fetch_results(cursor,dbqueries.metadata_part_query(part_id)) + del metadata_part_data[0]['updated'] + metadata_part_data[0]['participant'] = metadata_part_data[0]['entity_participant_id'] + del metadata_part_data[0]['entity_participant_id'] + metadata_participant=schema.MetadataParticipant(**metadata_part_data[0]) + + + # query to get metadata from sample table + metadata_data=self.fetch_results(cursor,dbqueries.metadata_sample_query(part_id)) + metadata_list=[] + for metadata in metadata_data: + del metadata['updated'] + metadata_list.append(schema.MetadataSample(**metadata)) + + # create file hits list + case_files_list=[] + for case_file in case_data: + del case_file['entity_participant_id'] + case_files_list.append(schema.CaseFile(**case_file)) + + case_object=schema.Case(id, + case_id=part_id, + primary_site=proj_data[0]['primary_site'], + demographic=schema.Demographic("not hispanic or latino","male","white"), + metadata_participant=metadata_participant, + metadata_sample=metadata_list, + project=self.projects[str(proj_id)], + summary=schema.Summary( + case_count=counts_data[0]['total'], + file_count=counts_data[1]['total'], + file_size=counts_data[2]['total'], + data_categories=self.get_data_categories("participant",part_id,cursor), + experimental_strategies=self.get_experimental_strategies("participant",part_id,cursor)), + files=schema.CaseFiles(hits=case_files_list)) + + + self.release_pool(conn,cursor) + return case_object - self.load_data() + + def get_project_aggregations(self, projects): # compile aggregations from project aggregates = {"primary_site": {}, "program__name": {}, - "project_id": {}, + "project_id": {}, "summary__data_categories__data_category": {}, "summary__experimental_strategies__experimental_strategy": {}} for project in projects: - add_key_increment(aggregates["primary_site"], project.primary_site[0]) + add_key_increment(aggregates["primary_site"],project.primary_site[0]) add_key_increment(aggregates["project_id"], project.project_id) add_key_increment(aggregates["program__name"], project.program.name) for item in project.summary.data_categories: @@ -78,29 +270,50 @@ def get_project_aggregations(self, projects): return project_aggregates + + + # get all counts for front page summary from db def get_current_counts(self): - self.load_data() - return self.data.CURRENT_COUNTS + + conn,cursor=self.get_pool() + counts_data=self.fetch_results(cursor,dbqueries.all_counts_query) + self.release_pool(conn,cursor) + return schema.Count( + projects=counts_data[0]['total'], + participants=counts_data[1]['total'], + samples=counts_data[2]['total'], + dataFormats=counts_data[3]['total'], + rawFiles=counts_data[4]['total'], + processedFiles=counts_data[5]['total']) + + def get_file_aggregations(self, files): - import schema - self.load_data() # aggregate file data aggregates = {"data_category": {}, "experimental_strategy": {}, "data_format": {}, "platform": {}, "cases__primary_site": {}, - "cases__project__project_id": {}, "access": {}} + "cases__project__project_id": {}, "cases__metadata_participant__age_2012": {}, + "cases__metadata_participant__totMETs1": {},"cases__metadata_participant__weight_lbs": {}, + "access": {}} for file in files: + add_key_increment(aggregates["data_category"], file.data_category) add_key_increment(aggregates["experimental_strategy"], file.experimental_strategy) add_key_increment(aggregates["data_format"], file.data_format) add_key_increment(aggregates["platform"], file.platform) add_key_increment(aggregates["access"], file.access) + project = file.cases.hits[0].project add_key_increment(aggregates["cases__primary_site"], project.primary_site[0]) add_key_increment(aggregates["cases__project__project_id"], project.project_id) + metadata_participant = file.cases.hits[0].metadata_participant + add_key_increment(aggregates["cases__metadata_participant__age_2012"], metadata_participant.age_2012) + add_key_increment(aggregates["cases__metadata_participant__totMETs1"], metadata_participant.totMETs1) + add_key_increment(aggregates["cases__metadata_participant__weight_lbs"], metadata_participant.weight_lbs) + file_aggregates = schema.FileAggregations( data_category=schema.Aggregations( buckets=[schema.Bucket(doc_count=count, key=key) for key,count in aggregates["data_category"].items()]), @@ -119,13 +332,14 @@ def get_file_aggregations(self, files): return file_aggregates - def get_case_aggregations(self, cases): - import schema - self.load_data() + + def get_case_aggregations(self, cases): # aggregate case data aggregates = {"demographic__ethnicity": {}, "demographic__gender": {}, + "metadata_participant__age_2012": {}, "metadata_participant__totMETs1": {}, + "metadata_participant__weight_lbs": {}, "demographic__race": {}, "primary_site": {}, "project__project_id": {}, "project__program__name": {}} @@ -133,10 +347,14 @@ def get_case_aggregations(self, cases): add_key_increment(aggregates["demographic__ethnicity"], case.demographic.ethnicity) add_key_increment(aggregates["demographic__gender"], case.demographic.gender) add_key_increment(aggregates["demographic__race"], case.demographic.race) + add_key_increment(aggregates["metadata_participant__age_2012"],case.metadata_participant.age_2012) + add_key_increment(aggregates["metadata_participant__totMETs1"],case.metadata_participant.totMETs1) + add_key_increment(aggregates["metadata_participant__weight_lbs"], case.metadata_participant.weight_lbs) add_key_increment(aggregates["primary_site"], case.primary_site) add_key_increment(aggregates["project__project_id"], case.project.project_id) add_key_increment(aggregates["project__program__name"], case.project.program.name) + case_aggregates=schema.CaseAggregations( demographic__ethnicity=schema.Aggregations( buckets=[schema.Bucket(doc_count=count, key=key) for key,count in aggregates["demographic__ethnicity"].items()]), @@ -144,6 +362,12 @@ def get_case_aggregations(self, cases): buckets=[schema.Bucket(doc_count=count, key=key) for key,count in aggregates["demographic__gender"].items()]), demographic__race=schema.Aggregations( buckets=[schema.Bucket(doc_count=count, key=key) for key,count in aggregates["demographic__race"].items()]), + metadata_participant__age_2012=schema.Aggregations( + buckets=[schema.Bucket(doc_count=count, key=key) for key,count in aggregates["metadata_participant__age_2012"].items()]), + metadata_participant__totMETs1=schema.Aggregations( + buckets=[schema.Bucket(doc_count=count, key=key) for key,count in aggregates["metadata_participant__totMETs1"].items()]), + metadata_participant__weight_lbs=schema.Aggregations( + buckets=[schema.Bucket(doc_count=count, key=key) for key,count in aggregates["metadata_participant__weight_lbs"].items()]), primary_site=schema.Aggregations( buckets=[schema.Bucket(doc_count=count, key=key) for key,count in aggregates["primary_site"].items()]), project__project_id=schema.Aggregations( @@ -153,11 +377,29 @@ def get_case_aggregations(self, cases): return case_aggregates + # get facet (currently not in use) def get_facets(self): return "null" # this is not currently being used + + # get total size of all files def get_cart_file_size(self): - self.load_data() - return self.data.CURRENT_FILE_SIZE + conn,cursor=self.get_pool() + file_data=self.fetch_results(cursor,dbqueries.files_size_query) + self.release_pool(conn,cursor) + return schema.FileSize(file_data[0]['sum_size']) + + def get_files_total(self): + conn,cursor=self.get_pool() + files_count_data=self.fetch_results(cursor,dbqueries.files_total_query) + self.release_pool(conn,cursor) + return files_count_data[0]['total'] + + def get_cases_total(self): + conn,cursor=self.get_pool() + cases_count_data=self.fetch_results(cursor,dbqueries.cases_total_query) + self.release_pool(conn,cursor) + return cases_count_data[0]['total'] data = Data() + diff --git a/dbqueries.py b/dbqueries.py new file mode 100644 index 0000000..fdfb02c --- /dev/null +++ b/dbqueries.py @@ -0,0 +1,83 @@ +# This file holds all queries run in database.py + + + +all_counts_query='''select count(id) as total from project + union all select count(id) as total from participant + union all select count(id) as total from sample + union all select count(distinct data_format) as total from file_sample + union all select count(id) as total from file_sample where type="rawFiles" + union all select count(id) as total from file_sample where type="processedFiles"''' +projects_query="select id from project" +version_query="select * from version order by updated desc limit 1" +files_query="select id from file_sample" +cases_query="select id from participant" +files_size_query="select sum(file_size) as sum_size from file_sample" +files_total_query="select count(id) as total from file_sample" +cases_total_query="select count(distinct id) as total from participant" + +def project_query(p_id): + return "select * from project where id =" + str(p_id) + +def project_counts_query(p_id): + query="select count(id) as total from file_sample where project='"+p_id+"'" + query=query+" union all " + query=query+"select count(distinct participant) as total from file_sample where project='"+p_id+"'" + query=query+" union all " + query=query+"select sum(file_size) as total from file_sample where project='"+p_id+"'" + return query + +def data_cat_query(table, p_id): + return "select distinct data_category from file_sample where "+ table+"='" + str(p_id)+"'" + +def data_cat_counts_query(table,p_id,data_cat): + query="select count(id) as total from file_sample where data_category='"+data_cat+"' and "+table+"='"+str(p_id)+"'" + query=query+" union all " + query=query+"select count(distinct participant) as total from file_sample where data_category='"+data_cat+"' and "+table+"='"+str(p_id)+"'" + return query + +def exp_str_query(table,p_id): + return "select distinct experimental_strategy from file_sample where "+ table+"='" + str(p_id) +"'" + +def exp_str_counts_query(table,p_id,exp_str): + query="select count(id) as total from file_sample where experimental_strategy='"+exp_str+"' and "+table+"='"+str(p_id)+"'" + query=query+" union all " + query=query+ "select count(distinct participant) as total from file_sample where experimental_strategy='"+exp_str+"' and "+table+"='"+str(p_id)+"'" + return query + +def file_query(f_id): + query='''select file_sample.*, + project.id as p_id, project.project_id as proj_id,project.primary_site, + participant.id as part_id, participant.age_2012, participant.totMETs1, participant.weight_lbs + from file_sample,project,participant where file_sample.id='''+str(f_id) + query=query+''' and file_sample.project=project.project_id and + file_sample.participant=participant.entity_participant_id''' + return query + +def case_query(p_id): + return '''select participant.entity_participant_id, file_sample.id, file_sample.experimental_strategy, + file_sample.data_category, file_sample.platform, file_sample.access,file_sample.data_format + from participant, file_sample + where participant.id='''+str(p_id)+" and file_sample.participant=participant.entity_participant_id" + +def case_counts_query(p_id): + query="select count(id) as total from participant where entity_participant_id="+str(p_id) + query=query+" union all " + query=query+ "select count(id) as total from file_sample where participant="+str(p_id) + query=query+" union all " + query=query+"select sum(file_size) as total from file_sample where participant="+str(p_id) + return query + +def case_project_query(p_id): + query="select distinct file_sample.project, project.id as p_id, project.primary_site " + query=query+"from file_sample, project where file_sample.participant='" + query=query+str(p_id)+"' and project.project_id=file_sample.project limit 1" + return query + + +def metadata_part_query(p_id): + return "select * from participant where entity_participant_id="+str(p_id) + +def metadata_sample_query(p_id): + return "select * from sample where participant="+str(p_id) + diff --git a/load_local_database.py b/load_local_database.py index f83f0f0..1a58ba8 100644 --- a/load_local_database.py +++ b/load_local_database.py @@ -23,7 +23,7 @@ def parse_arguments(args): required=False) parser.add_argument( "--key-file", - default="biom-mass-fdcadb440fdf.json", + default="/home/hutlab_public/compute_engine_service_account_key/biom-mass-8dc9ab934396.json", help="google project service account private key file path\n]", required=False) parser.add_argument( @@ -256,7 +256,7 @@ def main(): new_version = str(0.1) now = datetime.datetime.now() - release_date ="Date Release "+new_version+" "+ now.strftime("%b %d, %Y") + release_date ="Data Release "+new_version+" - "+ now.strftime("%b %d, %Y") commit ="commit_"+now.strftime("%m%d%Y") query_insert_version ='''INSERT INTO `version` ( commit, diff --git a/query_bigquery.py b/query_bigquery.py index 2d179ab..770c7ad 100644 --- a/query_bigquery.py +++ b/query_bigquery.py @@ -22,7 +22,7 @@ def parse_arguments(args): required=False) parser.add_argument( "--key-file", - default="biom-mass-fdcadb440fdf.json", + default="/home/hutlab_public/compute_engine_service_account_key/biom-mass-8dc9ab934396.json", help="google project service account private key file path\n]", required=False) parser.add_argument( diff --git a/schema.graphql b/schema.graphql old mode 100644 new mode 100755 index fe55875..5c73dc9 --- a/schema.graphql +++ b/schema.graphql @@ -23,16 +23,59 @@ type Case implements Node { primary_site: String submitter_id: String demographic: Demographic + metadata_participant: MetadataParticipant + metadata_sample: [MetadataSample] project: Project summary: Summary annotations: CaseAnnotations files: CaseFiles } +type MetadataParticipant { + id: Int + participant: Int + age_2012: Int + totMETs1: Float + weight_lbs: Float +} + +type MetadataSample + id: Int + project: String + sample: String + participant: Int + DaysSince1Jan12: Int + drAlcohol: Float + drB12: Float + drCalories: Float + drCarbs: Float + drCholine: Float + drFat: Float + drFiber: Float + drFolate: Float + drIron: Float + drProtein: Float + participant: Int + q2Alcohol: String + q2B12: String + q2Calories: String + q2Carbs: String + q2Choline: String + q2Fat: String + q2Fiber: String + q2Folate: String + q2Iron: String + q2Protein: String + Time: String + week: Int + type CaseAggregations { demographic__ethnicity: Aggregations demographic__gender: Aggregations demographic__race: Aggregations + metadata_participant__age_2012: Aggregations + metadata_participant__totMETs1: Aggregations + metadata_participant__weight_lbs: Aggregations primary_site: Aggregations project__project_id: Aggregations project__program__name: Aggregations @@ -180,6 +223,7 @@ type FileCase implements Node { case_id: String project: Project demographic: Demographic + metadata_participant: MetadataParticipant primary_site: String } diff --git a/schema.py b/schema.py index 13b23d4..ab40d3b 100644 --- a/schema.py +++ b/schema.py @@ -91,6 +91,43 @@ class Demographic(graphene.ObjectType): gender = graphene.String() race = graphene.String() +class MetadataParticipant(graphene.ObjectType): + id = graphene.Int() + participant = graphene.Int() + age_2012 = graphene.Int() + totMETs1 = graphene.Float() + weight_lbs = graphene.Float() + +class MetadataSample(graphene.ObjectType): + id = graphene.Int() + project = graphene.String() + sample = graphene.String() + participant = graphene.Int() + DaysSince1Jan12 = graphene.Int() + drAlcohol = graphene.Float() + drB12 = graphene.Float() + drCalories = graphene.Float() + drCarbs = graphene.Float() + drCholine = graphene.Float() + drFat = graphene.Float() + drFiber = graphene.Float() + drFolate = graphene.Float() + drIron = graphene.Float() + drProtein = graphene.Float() + participant = graphene.Int() + q2Alcohol = graphene.String() + q2B12 = graphene.String() + q2Calories = graphene.String() + q2Carbs = graphene.String() + q2Choline = graphene.String() + q2Fat = graphene.String() + q2Fiber = graphene.String() + q2Folate = graphene.String() + q2Iron = graphene.String() + q2Protein = graphene.String() + Time = graphene.String() + week = graphene.Int() + class FileCase(graphene.ObjectType): class Meta: interfaces = (graphene.relay.Node,) @@ -98,6 +135,7 @@ class Meta: case_id = graphene.String() project = graphene.Field(Project) demographic = graphene.Field(Demographic) + metadata_participant = graphene.Field(MetadataParticipant) primary_site = graphene.String() class FileCaseConnection(graphene.relay.Connection): @@ -137,7 +175,7 @@ class Meta: type = graphene.String() def resolve_file_id(self, info): - return self.name + return self.file_id def resolve_type(self, info): return self.data_format @@ -160,6 +198,7 @@ class Meta: total = graphene.Int() def resolve_total(self, info): + # return data.get_files_total() return len(self.edges) class Bucket(graphene.ObjectType): @@ -214,6 +253,9 @@ class CaseAggregations(graphene.ObjectType): demographic__ethnicity = graphene.Field(Aggregations) demographic__gender = graphene.Field(Aggregations) demographic__race = graphene.Field(Aggregations) + metadata_participant__age_2012 = graphene.Field(Aggregations) + metadata_participant__totMETs1 = graphene.Field(Aggregations) + metadata_participant__weight_lbs = graphene.Field(Aggregations) primary_site = graphene.Field(Aggregations) project__project_id = graphene.Field(Aggregations) project__program__name = graphene.Field(Aggregations) @@ -280,8 +322,9 @@ class Meta: case_id = graphene.String() primary_site = graphene.String() submitter_id = graphene.String() - demographic = graphene.Field(Demographic) + metadata_participant = graphene.Field(MetadataParticipant) + metadata_sample = graphene.List(MetadataSample) project = graphene.Field(Project) summary = graphene.Field(Summary) annotations = graphene.Field(CaseAnnotations) @@ -298,6 +341,7 @@ class Meta: total = graphene.Int() def resolve_total(self, info): + #return data.get_cases_total() return len(self.edges) class RepositoryCases(graphene.ObjectType): diff --git a/server.py b/server.py index 4154751..6d626e0 100644 --- a/server.py +++ b/server.py @@ -10,11 +10,13 @@ import os import flask +import flask_cors import flask_graphql import graphene import schema -import const +#import const +from database import data NAME = "firecloud_graphql" HOST = "0.0.0.0" @@ -41,7 +43,8 @@ def process_query(request, schema): def main(): # create the graphql flask app app = flask.Flask(NAME) - + # allow initial OPTIONS requests + flask_cors.CORS(app) # add the root graphql queries @app.route('/graphql', methods=["POST"]) def get_root_schema(): @@ -55,8 +58,8 @@ def get_schema(name): # add static endpoint for version/status @app.route('/status', methods=["GET"]) def get_version(): - return flask.jsonify(const.VERSION) - + return flask.jsonify(data.get_current_version()) + # app.debug = True # add end point for graphql gui app.add_url_rule('/test', view_func=flask_graphql.GraphQLView.as_view( 'test', schema=graphene.Schema(query=schema.Query, auto_camelcase=False), graphiql=True))